Closed
Description
TypeScript Version:
nightly (1.9.0-dev.20160217)
Code
export class A {
s: string;
}
export class B extends A {
constructor(public s?: string) {
super();
}
}
Expected behavior:
My understanding is that constructor(public s?: string)
is interpreted to mean the field is optional, i.e. desugars to:
s?: string;
constructor(s?: string) {
this.s = s;
}
Since subclasses can only override fields with subtypes and string | undefined
is a supertype of string
, this should be an error.
Actual behavior:
The code is accepted. Moreover the produced d.ts file is the following:
declare class A {
s: string;
}
declare class B extends A {
s?: string;
constructor(s?: string);
}
which itself is rejected in further compilations with t.d.ts(4,15): error TS2415: Class 'B' incorrectly extends base class 'A'.