Skip to content

Extends a Class will make losing and corrupted types in a child class. #42541

Closed
@jonlepage

Description

@jonlepage

When we add types on properties base class, if a child class extends this base class, we will lost types and get corrupted behavior.
Actually is seem affected by keyof T, i not tested all others types, but this one make coruptions.
From what i understand, the child class seem ignore the type from parent !
Or maybe i miss understand the logic here ? if you have alternative to suggest ?

sample js:

const TypesEnum = {
	abc: 'abc',
	abcd: 'abcd',
	abcde: 'abcde',
};

export class Base {
	/**@type {keyof TypesEnum} - all work fine here, default null for the example purpose */
	_test = null;
	constructor(data) {}
}

export class A extends Base {
       /** type are corrupted with vscode Intelisence , we should see and allowed to use the result of keyof TypesEnum ! */
	_test = 'abc'; //lint a error and we lost intellisense in Vscode (ctrl+space)!
	constructor(data) {
		super();
	}
}

🙁 Actual behavior

image
we lost intellisence in Vscode ! and type become corupted.
image

🙂 Expected behavior

type keyof should be heritate in the child class !
image
Without write again /**@type {keyof TypesEnum} */ in the child class !


tsc versions: 4.1.3 and 4.2.0-dev.20210128
Version : 1.52.1 (user setup)
Commit : ea3859d4ba2f3e577a159bc91e3074c5d85c0523
Date : 2020-12-16T16:34:46.910Z
Electron : 9.3.5
Chrome : 83.0.4103.122
Node.js : 12.14.1
V8 : 8.3.110.13-electron.0
OS : Windows_NT x64 10.0.19042

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions