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
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.
The text was updated successfully, but these errors were encountered:
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
TypeScript Version: 3.0.1-insiders.20180726
Search Terms: I don't even
Code
Expected behavior:
No compiler error
Actual behavior:
Type '{}' is not assignable to type 'NonNullable<TEndpoint["t"]>'.
Playground Link:
https://www.typescriptlang.org/play/index.html#src=class%20Endpoint%3CT%20%3D%20%7B%7D%3E%20%7B%20%2F%2F%20This%20actually%20has%202%2B%20parameters%0D%0A%20%20%20%20t!%3A%20T%3B%0D%0A%7D%0D%0A%0D%0Aclass%20ConfigReader%3CTEndpoint%20extends%20Endpoint%3E%20%7B%0D%0A%20%20%20%20constructor(readonly%20endpoint%3A%20TEndpoint)%20%7B%20%7D%0D%0A%0D%0A%20%20%20%20getValue()%3A%20NonNullable%3CTEndpoint%5B't'%5D%3E%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20this.endpoint.t%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A
Motivation:
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 onConfigReader
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.
The text was updated successfully, but these errors were encountered: