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
{{ message }}
Repository navigation
Inferred index types on type parameters don't propagate through NonNullable<T> #26942
classEndpoint<T={}>{// This actually has 2+ parameterst!: T;}classConfigReader<TEndpointextendsEndpoint>{constructor(readonlyendpoint: TEndpoint){}getValue(): NonNullable<TEndpoint['t']>{returnthis.endpoint.t;}}
Expected behavior:
No compiler error
Actual behavior:
Type '{}' is not assignable to type 'NonNullable<TEndpoint["t"]>'.
In my actual code, ConfigReader has 4 type parameters, each of which is a further config class with even more nested parameters. I'm trying to avoid putting ~15 type parameters on ConfigReader by bundling them in this fashion, accepting a single type parameter for each top-level thing and accessing their nested type parameters via [] notation.
This works perfectly (so far), except for this issue.
We currently don't have a way to validate that the control flow of any particular function satisfies a conditional type (which NonNullable is) - a type assertion is needed here to indicate that you've correctly handled the case where this.endpoint.t is null/undefined
Activity
RyanCavanaugh commentedon Sep 20, 2018
We currently don't have a way to validate that the control flow of any particular function satisfies a conditional type (which
NonNullableis) - a type assertion is needed here to indicate that you've correctly handled the case wherethis.endpoint.tis null/undefined