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
classTest{publicprop: StringConstructor=String;publictest!: InstanceType<this['prop']>;publicfn(){letv1: InstanceType<StringConstructor>,v2: InstanceType<this['prop']>,v3: this['prop'];v1='str';// OKv2='str';// Type '"str"' is not assignable to type 'InstanceType<this["prop"]>'.v3=String;// OK, TS knows type of this['prop']this.test='str';// Type '"str"' is not assignable to type 'InstanceType<this["prop"]>'.}}letobj=newTest();obj.test='str';// OK
Expected behavior:
InstanceType<this['prop']> as String
Actual behavior:
Error: Type '"str"' is not assignable to type 'InstanceType<this["prop"]>'.
The text was updated successfully, but these errors were encountered:
This is the intended behavioral difference between a this types and the alternative name Test['prop'] - a subtype of Test might have a more specific type of prop
TypeScript Version: 3.6.4
Search Terms:
InstanceType of this
Code
Expected behavior:
InstanceType<this['prop']> as String
Actual behavior:
Error: Type '"str"' is not assignable to type 'InstanceType<this["prop"]>'.
The text was updated successfully, but these errors were encountered: