You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You broke the Component<CustomElement> type by mapping in your interface:
Let's fix this:
Now we have arrived at the same problem the right way
The factory(() => string) function compares two types: Property<E, V = () => string> and Property<E, V = string>
So let's simplify the task to...
typeProperty<T>=|(Textendsstring|number|boolean|undefined ? T : never)|((lastValue: T)=>T)functionfactory<T>(value: Property<T>): Property<T>{returnvalue;}// Type 'string' is not assignable to type '() => string'.ts(2322)factory(()=>"")typeExtractOrigin<P>=PextendsProperty<infer Origin> ? Origin : never;typeSecondGeneric=ExtractOrigin<()=>string>// We expect `string` but `string | (() => string)` comes back!
It looks like using type unions along with conditional types breaks typescript.
And your solution actually works for this case, although it looks absurd.
I assume that after the conditional type, all other elements of the type union break down.
Therefore, conditional types need to be moved to the end of type unions throughout the code. I found several more such cases in the /** Store **/ section.
Hi @smalluban!
I was working on some side project and noticed that the type inferencing when passing properties as arguments has a small problem.
When passing a computed getter function to a factory function, the property is inferred as a function:
I was able to reproduce the issue here and I show a possible fix:
https://stackblitz.com/edit/vitejs-vite-xmqndb?file=package.json,src%2Fmain.ts,tsconfig.json&terminal=dev
In my experimenting, I found out that rearranging the union type for Property made a difference:
If you think re-arranging the union type wouldn't create any unforseen negative side-effects, I'm happy to author a quick PR. 👍
The text was updated successfully, but these errors were encountered: