TypeScript Version: 3.0.1-insiders.20180726
Search Terms: I don't even
Code
class Endpoint<T = {}> { // This actually has 2+ parameters
t!: T;
}
class ConfigReader<TEndpoint extends Endpoint> {
constructor(readonly endpoint: TEndpoint) { }
getValue(): NonNullable<TEndpoint['t']> {
return this.endpoint.t;
}
}
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 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.
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,
ConfigReaderhas 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 onConfigReaderby 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.