question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to map TypeScript union types

See original GitHub issue

Hi, how can we map TypeScript union types in kotlinjs ?

For example in ReactQuery there are signatures like this:

queryClient.setQueryData(queryKey, updater)

queryKey: QueryKey
updater: TData | (oldData: TData | undefined) => TData

(I asked ReactQuery to avoid such signatures: https://github.com/TanStack/query/issues/3740 )

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
turanskycommented, Jun 24, 2022

@frhack You can close it as author (and others, which solved for you)

1reaction
frhackcommented, Jun 24, 2022

Usually we use more flexible signature. In described case it will be:

updater: (oldData: TData?) -> TData

In common initial signature is fine. Looks like it will work in Kotlin, when unions types will be supported.

Indeed the provided signature is more general and so to pass a simple value I just passed a lambda that returns that value

I got an answer from ReactQuery team:

in v4, the signature has been changed to:

updater: (oldData: TData | undefined) => TData | undefined

https://github.com/TanStack/query/issues/3740

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript: Map union type to another union type
You can use conditional type for distributing over the members of the union type (conditional type always takes only one branch and is...
Read more >
Map over a union type | Total TypeScript
TypeScript actually automatically maps over each member of the union when it's doing a conditional type check.
Read more >
Creating a mapped type | Learn TypeScript
A mapped type is the process of creating a new type by mapping type ... The in operator maps over each item in...
Read more >
How to make a map object type from a union type in TypeScript?
To make a simple map object type from a union type, you can use the in operator in combination with Index Signature syntax...
Read more >
Documentation - Mapped Types - TypeScript
You can map over arbitrary unions, not just unions of string | number | symbol , but unions of any type: ts. type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found