Note some related issues for doing this with properties rather than methods: #3667, #6118, #1373.
Goal
We want to make it easier for users to derive types without rewriting the same parameter signature every time
classBase{method(x: number){// ...}}classDerivedextendsBase{method(x){// 'x' should have the type 'number' here.}}Potential ideas
- Only enable in
noImplicitAny (doesn't work for default initializers 😞) - Revert to
any in all locations, opt in with another strictness flag (😞) - Something else? 😕
Potential issues
Default initializers with more capable derived types
classA{a=1;}classBextendsA{b=2;}classBase{method(x: A){// ...}}classDerivedextendsBase{method(x=newB){x.b;// Today, 'x' has type 'B' which is technically unsound// but that's just what we do. Does changing this to 'A' break things?}}Default initializers that become less-capable via contextual types
classBase{method(x: "a"|"b"){// ...}}classDerivedextendsBase{method(x="a"){// We have to make sure 'x' doesn't have type '"a"'// which is both unsound and less useful.}}Distinction between properties and methods
Would this work?
classBase{method=(x: number)=>{// ...}}classDerivedextendsBase{method(x){// Does 'x' have the type 'number' here?}}What about this?
classBase{method(x: number){// ...}}classDerivedextendsBase{method=(x)=>{// Does 'x' have the type 'number' here?}}
Keywords: base type derived contextual contextually inherit methods implicit any
Note some related issues for doing this with properties rather than methods: #3667, #6118, #1373.
Goal
We want to make it easier for users to derive types without rewriting the same parameter signature every time
Potential ideas
noImplicitAny(doesn't work for default initializers 😞)anyin all locations, opt in with another strictness flag (😞)Potential issues
Default initializers with more capable derived types
Default initializers that become less-capable via contextual types
Distinction between properties and methods
Would this work?
What about this?
Keywords: base type derived contextual contextually inherit methods implicit any