Content pfp
Content
@
0 reply
0 recast
2 reactions

Darryl Yeo 🛠️ pfp
Darryl Yeo 🛠️
@darrylyeo
Any TypeScript gurus in the house who can help me troubleshoot this? What am I fundamentally misunderstanding about type parameters / conditionals here?
8 replies
1 recast
11 reactions

Marc BHE Season 🍖☣️ pfp
Marc BHE Season 🍖☣️
@bighamenergy.eth
maybe it's easier to find out with a link from here https://www.typescriptlang.org/play/ but as far as i can read from the images is because is not able to cast the type, possibly because the optionals
1 reply
0 recast
1 reaction

Darryl Yeo 🛠️ pfp
Darryl Yeo 🛠️
@darrylyeo
Playground link is too long for Warpcast... https://warpcast.com/darrylyeo/0x34016cc1
1 reply
0 recast
2 reactions

Marc BHE Season 🍖☣️ pfp
Marc BHE Season 🍖☣️
@bighamenergy.eth
Maybe you need some primitives like predicates. ``` const isTypeA = (x: Type): x is Type.A => x === Type.A ... ``` with that you can do `isTypeA` and will infer the right type will try to see what's with the current snippet and get back to you
1 reply
0 recast
1 reaction

Darryl Yeo 🛠️ pfp
Darryl Yeo 🛠️
@darrylyeo
Nope, tried that https://warpcast.com/darrylyeo/0x0dfee310
1 reply
0 recast
0 reaction

Marc BHE Season 🍖☣️ pfp
Marc BHE Season 🍖☣️
@bighamenergy.eth
https://codesandbox.io/p/devbox/fp9ryk seems to be that it's the optionals... wrote a file called transform and added a variation and some comments
2 replies
0 recast
1 reaction

Darryl Yeo 🛠️ pfp
Darryl Yeo 🛠️
@darrylyeo
Thanks! This does work, but now I'm wondering if I'd be able to group multiple unique parameters under the same umbrella conditional instead of defining a conditional for each parameter.
2 replies
0 recast
1 reaction

Darryl Yeo 🛠️ pfp
Darryl Yeo 🛠️
@darrylyeo
```ts type Type = 'A' | 'B' type From< T extends Type = Type, > = { type: Type A: T extends 'A' ? number : never B: T extends 'B' ? string : never } type To< T extends Type = Type, > = { type: Type a?: T extends 'A' ? number : never b?: T extends 'B' ? string : never } const transform = < T extends Type = Type >( { type, A, B }: From<T>, ): To<T> => ({ type, ...type === 'A' && { a: A, }, ...type === 'B' && { b: B, }, }) ```
1 reply
0 recast
1 reaction

Marc BHE Season 🍖☣️ pfp
Marc BHE Season 🍖☣️
@bighamenergy.eth
yeah, time to put those brains to work haha. Will try to think in a way, but AFAIK you can't "iterate" in types
1 reply
0 recast
2 reactions