S
SolidJS•9mo ago
Jakob

`<Dynamic>` function prop args are `any`

Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
No description
11 Replies
Jasmin
Jasmin•9mo ago
Interesting :thinkies: Typescript just seems to give up if you hover on the onValueChange prop it's typed correctly. Maybe @jer3m01 or @Otonashi know why this is happening
Otonashi
Otonashi•9mo ago
afaict this is caused by https://github.com/solidjs/solid/pull/1248, which intentionally adds some magic to prevent the type of props from affecting the inferred type of component; not sure what to do about it reverting the pr and applying
- export type ValidComponent = keyof JSX.IntrinsicElements | Component<any> | (string & {});
+ export type ValidComponent = keyof JSX.IntrinsicElements | Component<never> | (string & {});
- export type ValidComponent = keyof JSX.IntrinsicElements | Component<any> | (string & {});
+ export type ValidComponent = keyof JSX.IntrinsicElements | Component<never> | (string & {});
seems promising, but that breaks accessing props.component so anyone relying on that will have to work around it i'm not sure if there's a better supertype in this case, ideally it would be something like Component<{ [x: string]?: unknown }> but that's invalid ts
mdynnl
mdynnl•9mo ago
strange thing is it seems to infer correctly when there's an error lol
No description
mdynnl
mdynnl•9mo ago
tbh i don't know what i was doing playing around typescript with basic ts knowledge 😆
Jasmin
Jasmin•9mo ago
typescript often stops checking if there is an error at an other place. this is common
mdynnl
mdynnl•9mo ago
like multiple passes right? even then it would still check as much as possible. at least that's what it seems to me
No description
Otonashi
Otonashi•9mo ago
No description
Otonashi
Otonashi•9mo ago
not just any error that causes inference to change my guess is if the shape of the props is invalid typescript recalculates them, otherwise it doesn't jsx ignores properties with hyphens
Otonashi
Otonashi•9mo ago
not sure why the function call form works differently but changing the type of value gives a similar result
No description
Otonashi
Otonashi•9mo ago
so initially it resolves onValueChange to any => any, which will pass a check against the presumably later resolved generic constraint however if the props fail overall then it'll rerun and narrow onValueChange to string => void (only to fail for the initial reason) well everything is a guess without knowing ts internals
Want results from more Discord servers?
Add your server