0

This works in typescript v4.1.3(playground) but doesn't work in v3.9.7(playground)

const uniqueMap = <K, V>(items: [key: K, val: V][]) =>
    new Map(items).values()

How to make this work. I am trying to make it generic so that I can use it for any kind of data.

My current work around

const uniqueMap = (items: any[]) => new Map(items).values()
1
  • You are using new feature from ts 4, that is why it is not working in ts 3.9. Have a look: typescriptlang.org/docs/handbook/release-notes/…. I would suggest not to use labels as your ts compiler doesn't support it Commented Feb 4, 2021 at 9:17

1 Answer 1

1

Tuple labels are a TS 4.0 feature and not really all that useful, imo. Simplifying your code like this makes it compatible in all modern versions of TS:

const uniqueMap = <K, V>(items: [K, V][]) =>
    new Map(items).values()

Playground

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.