-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Error on class fields accesses through super in JS files
#55892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
292ab59
49d3554
44010a3
05b21a0
23ec307
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| index.js(20,22): error TS2855: Class field 'roots' defined by the parent class is not accessible in the child class via super. | ||
| index.js(23,22): error TS2855: Class field 'foo' defined by the parent class is not accessible in the child class via super. | ||
| index.js(26,22): error TS2855: Class field 'justProp' defined by the parent class is not accessible in the child class via super. | ||
| index.js(29,22): error TS2855: Class field ''literalElementAccess'' defined by the parent class is not accessible in the child class via super. | ||
|
|
||
|
|
||
| ==== index.js (4 errors) ==== | ||
| // https://github.com/microsoft/TypeScript/issues/55884 | ||
|
|
||
| class YaddaBase { | ||
| constructor() { | ||
| this.roots = "hi"; | ||
| /** @type number */ | ||
| this.justProp; | ||
| /** @type string */ | ||
| this['literalElementAccess']; | ||
|
|
||
| this.b() | ||
| } | ||
| accessor b = () => { | ||
| this.foo = 10 | ||
| } | ||
| } | ||
|
|
||
| class DerivedYadda extends YaddaBase { | ||
| get rootTests() { | ||
| return super.roots; | ||
| ~~~~~ | ||
| !!! error TS2855: Class field 'roots' defined by the parent class is not accessible in the child class via super. | ||
| } | ||
| get fooTests() { | ||
| return super.foo; | ||
| ~~~ | ||
| !!! error TS2855: Class field 'foo' defined by the parent class is not accessible in the child class via super. | ||
| } | ||
| get justPropTests() { | ||
| return super.justProp; | ||
| ~~~~~~~~ | ||
| !!! error TS2855: Class field 'justProp' defined by the parent class is not accessible in the child class via super. | ||
| } | ||
| get literalElementAccessTests() { | ||
| return super.literalElementAccess; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test for Also, can you just add a test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good catch. It doesn't work correctly today (TS playground) even in TS files. For that reason - I'd say that this is a separate issue. I can look into it as well but I'd prefer to explore it separately.
Sure thing, just added it. |
||
| ~~~~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2855: Class field ''literalElementAccess'' defined by the parent class is not accessible in the child class via super. | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| //// [tests/cases/compiler/classFieldSuperNotAccessibleJs.ts] //// | ||
|
|
||
| === index.js === | ||
| // https://github.com/microsoft/TypeScript/issues/55884 | ||
|
|
||
| class YaddaBase { | ||
| >YaddaBase : Symbol(YaddaBase, Decl(index.js, 0, 0)) | ||
|
|
||
| constructor() { | ||
| this.roots = "hi"; | ||
| >this.roots : Symbol(YaddaBase.roots, Decl(index.js, 3, 19)) | ||
| >this : Symbol(YaddaBase, Decl(index.js, 0, 0)) | ||
| >roots : Symbol(YaddaBase.roots, Decl(index.js, 3, 19)) | ||
|
|
||
| /** @type number */ | ||
| this.justProp; | ||
| >this.justProp : Symbol(YaddaBase.justProp, Decl(index.js, 4, 26)) | ||
| >this : Symbol(YaddaBase, Decl(index.js, 0, 0)) | ||
| >justProp : Symbol(YaddaBase.justProp, Decl(index.js, 4, 26)) | ||
|
|
||
| /** @type string */ | ||
| this['literalElementAccess']; | ||
| >this : Symbol(YaddaBase, Decl(index.js, 0, 0)) | ||
| >'literalElementAccess' : Symbol(YaddaBase['literalElementAccess'], Decl(index.js, 6, 22)) | ||
|
|
||
| this.b() | ||
| >this.b : Symbol(YaddaBase.b, Decl(index.js, 11, 5)) | ||
| >this : Symbol(YaddaBase, Decl(index.js, 0, 0)) | ||
| >b : Symbol(YaddaBase.b, Decl(index.js, 11, 5)) | ||
| } | ||
| accessor b = () => { | ||
| >b : Symbol(YaddaBase.b, Decl(index.js, 11, 5)) | ||
|
|
||
| this.foo = 10 | ||
| >this.foo : Symbol(YaddaBase.foo, Decl(index.js, 12, 24)) | ||
| >this : Symbol(YaddaBase, Decl(index.js, 0, 0)) | ||
| >foo : Symbol(YaddaBase.foo, Decl(index.js, 12, 24)) | ||
| } | ||
| } | ||
|
|
||
| class DerivedYadda extends YaddaBase { | ||
| >DerivedYadda : Symbol(DerivedYadda, Decl(index.js, 15, 1)) | ||
| >YaddaBase : Symbol(YaddaBase, Decl(index.js, 0, 0)) | ||
|
|
||
| get rootTests() { | ||
| >rootTests : Symbol(DerivedYadda.rootTests, Decl(index.js, 17, 38)) | ||
|
|
||
| return super.roots; | ||
| >super.roots : Symbol(YaddaBase.roots, Decl(index.js, 3, 19)) | ||
| >super : Symbol(YaddaBase, Decl(index.js, 0, 0)) | ||
| >roots : Symbol(YaddaBase.roots, Decl(index.js, 3, 19)) | ||
| } | ||
| get fooTests() { | ||
| >fooTests : Symbol(DerivedYadda.fooTests, Decl(index.js, 20, 5)) | ||
|
|
||
| return super.foo; | ||
| >super.foo : Symbol(YaddaBase.foo, Decl(index.js, 12, 24)) | ||
| >super : Symbol(YaddaBase, Decl(index.js, 0, 0)) | ||
| >foo : Symbol(YaddaBase.foo, Decl(index.js, 12, 24)) | ||
| } | ||
| get justPropTests() { | ||
| >justPropTests : Symbol(DerivedYadda.justPropTests, Decl(index.js, 23, 5)) | ||
|
|
||
| return super.justProp; | ||
| >super.justProp : Symbol(YaddaBase.justProp, Decl(index.js, 4, 26)) | ||
| >super : Symbol(YaddaBase, Decl(index.js, 0, 0)) | ||
| >justProp : Symbol(YaddaBase.justProp, Decl(index.js, 4, 26)) | ||
| } | ||
| get literalElementAccessTests() { | ||
| >literalElementAccessTests : Symbol(DerivedYadda.literalElementAccessTests, Decl(index.js, 26, 5)) | ||
|
|
||
| return super.literalElementAccess; | ||
| >super.literalElementAccess : Symbol(YaddaBase['literalElementAccess'], Decl(index.js, 6, 22)) | ||
| >super : Symbol(YaddaBase, Decl(index.js, 0, 0)) | ||
| >literalElementAccess : Symbol(YaddaBase['literalElementAccess'], Decl(index.js, 6, 22)) | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| //// [tests/cases/compiler/classFieldSuperNotAccessibleJs.ts] //// | ||
|
|
||
| === index.js === | ||
| // https://github.com/microsoft/TypeScript/issues/55884 | ||
|
|
||
| class YaddaBase { | ||
| >YaddaBase : YaddaBase | ||
|
|
||
| constructor() { | ||
| this.roots = "hi"; | ||
| >this.roots = "hi" : "hi" | ||
| >this.roots : any | ||
| >this : this | ||
| >roots : any | ||
| >"hi" : "hi" | ||
|
|
||
| /** @type number */ | ||
| this.justProp; | ||
| >this.justProp : number | ||
| >this : this | ||
| >justProp : number | ||
|
|
||
| /** @type string */ | ||
| this['literalElementAccess']; | ||
| >this['literalElementAccess'] : any | ||
| >this : this | ||
| >'literalElementAccess' : "literalElementAccess" | ||
|
|
||
| this.b() | ||
| >this.b() : void | ||
| >this.b : () => void | ||
| >this : this | ||
| >b : () => void | ||
| } | ||
| accessor b = () => { | ||
| >b : () => void | ||
| >() => { this.foo = 10 } : () => void | ||
|
|
||
| this.foo = 10 | ||
| >this.foo = 10 : 10 | ||
| >this.foo : number | undefined | ||
| >this : this | ||
| >foo : number | undefined | ||
| >10 : 10 | ||
| } | ||
| } | ||
|
|
||
| class DerivedYadda extends YaddaBase { | ||
| >DerivedYadda : DerivedYadda | ||
| >YaddaBase : YaddaBase | ||
|
|
||
| get rootTests() { | ||
| >rootTests : string | ||
|
|
||
| return super.roots; | ||
| >super.roots : string | ||
Andarist marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| >super : YaddaBase | ||
| >roots : string | ||
| } | ||
| get fooTests() { | ||
| >fooTests : number | undefined | ||
|
|
||
| return super.foo; | ||
| >super.foo : number | undefined | ||
| >super : YaddaBase | ||
| >foo : number | undefined | ||
| } | ||
| get justPropTests() { | ||
| >justPropTests : number | ||
|
|
||
| return super.justProp; | ||
| >super.justProp : number | ||
| >super : YaddaBase | ||
| >justProp : number | ||
| } | ||
| get literalElementAccessTests() { | ||
| >literalElementAccessTests : any | ||
|
|
||
| return super.literalElementAccess; | ||
| >super.literalElementAccess : any | ||
| >super : YaddaBase | ||
| >literalElementAccess : any | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // @strict: true | ||
| // @checkJs: true | ||
| // @target: esnext | ||
| // @noEmit: true | ||
|
|
||
| // @filename: index.js | ||
|
|
||
| // https://github.com/microsoft/TypeScript/issues/55884 | ||
|
|
||
| class YaddaBase { | ||
| constructor() { | ||
| this.roots = "hi"; | ||
| /** @type number */ | ||
| this.justProp; | ||
| /** @type string */ | ||
| this['literalElementAccess']; | ||
|
|
||
| this.b() | ||
| } | ||
| accessor b = () => { | ||
| this.foo = 10 | ||
| } | ||
| } | ||
|
|
||
| class DerivedYadda extends YaddaBase { | ||
| get rootTests() { | ||
| return super.roots; | ||
| } | ||
| get fooTests() { | ||
| return super.foo; | ||
| } | ||
| get justPropTests() { | ||
| return super.justProp; | ||
| } | ||
| get literalElementAccessTests() { | ||
| return super.literalElementAccess; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.