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
If I redefine property type to be more specific in the derived class, it makes it undefined.
class A {
prop: string;
constructor(test: string) {
this.prop = test;
}
}
class B extends A {
prop: 'str1' | 'str2';
constructor(test: 'str1' | 'str2') {
super(test);
}
}
const test = new B('str2');
console.log(test.prop);
I know, I didn't explicitly set it in the constructor of class B, however, when I compile the file with TSC it works differently: I can access the prop and it's not undefined.
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
If I redefine property type to be more specific in the derived class, it makes it undefined.
I know, I didn't explicitly set it in the constructor of class B, however, when I compile the file with TSC it works differently: I can access the
prop
and it's notundefined
.Input code
No response
Config
Playground link (or link to the minimal reproduction)
https://play.swc.rs/?version=1.6.7&code=H4sIAAAAAAAAA32PywrCMBBF94X%2Bw92l2RR0aXBh%2F0TiUAshCUmKQu2%2Fm4fBB%2BqshsmdMycAINXRexywtA1yWWfsDj64SY%2BibepYGh1nswzGdYF8qBH%2B3ATCefJ9AmCPFBL1aS3NWnnl6gC6BtKnL%2FdZpG8YbrnZsr8iH9k3Iz9bKjn%2BWyYRs2%2FU1nTB0D1I4jViFPXKjBmWP8nFHeglkztBAQAA&config=H4sIAAAAAAAAA1VPOw7DIAzdOQXy3KHN0KF36CEQdSIqfsKOVBTl7oUE0maz38fveRFSwps0PORSxrJElQjTsReEsmf1KQhwjkg6mchw6SxTpUZlCTdo3RlglSbk6kIarsOtOcCGQNgdDXPGmzH%2FZ%2BrgYkKis7BKlZ8snhNFSwUXXvNGtl9q373BHX6iHnYcBkPP7uQ0o1i%2FsnkCbBcBAAA%3D
SWC Info output
No response
Expected behavior
this.prop should be defined
Actual behavior
No response
Version
1.6.6
Additional context
No response
The text was updated successfully, but these errors were encountered: