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
This is beyond the reasoning capabilities of the type checker. The checker would need to understand that StringPropertyNames<T> is constrained such that T[StringPropertyNames<T>] is constrained to type string. We don't produce such transitive constraints and it would definitely be complex to do so. I'm afraid you'll need a type assertion for this one.
TypeScript Version: 3.5.0-dev.20190504
Search Terms:
Description
I've been trying to make a generic function which receives and object T and receives a string property name of that object T.
I used https://www.typescriptlang.org/docs/handbook/advanced-types.html as an example (section: Distributive conditional types)
I've come up with a solution that works without generics, but when I change the explicit types to a generic type typescript won't compile.
Code
Expected behavior:
The generic example compiles
Actual behavior:
The generic example doesn't compile
Playground Link:
Playground
Related Issues:
#30295
#29505
#29662
The text was updated successfully, but these errors were encountered: