-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
The title of the bug should probably be improved - I was not able to come up with something that encapsulates the issue.
TypeScript Version: 2.1.5, compiling using --strictNullChecks
This issue seems not to be present in the TypeScript playground (2.1.4-insiders.20161201):
Code
interface Foo {
foo: number|null;
}
export class Base<T extends Foo> {
public style: Readonly<T>;
public styleDirect: Readonly<Foo>;
public reqNumber(a: number) {
}
public reqNumberNull(a: number|null) {
}
public method() {
// works
this.reqNumberNull(this.style.foo);
// works
this.reqNumber(this.styleDirect.foo || 0);
// does not work
this.reqNumber(this.style.foo || 0);
}
}
Expected behavior:
All three method calls should compile correctly.
Actual behavior:
test.ts(26,24): error TS2345: Argument of type 'T["foo"] | 0' is not assignable to parameter of type 'number'.
Type 'T["foo"]' is not assignable to type 'number'.
Type 'number | null' is not assignable to type 'number'.
Type 'null' is not assignable to type 'number'.
Nipheris, IOuser, timocov, bobunderforest and Knagis
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed