-
Notifications
You must be signed in to change notification settings - Fork 748
Fix TS2540 not reported for readonly properties accessed through imports #2179
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
19c0f8b
Initial plan
Copilot 0c8aeca
Fix TS2540 error not reported for readonly properties from imports
Copilot 6ebb498
Add module directive to test and generate baselines
Copilot 34878cc
Accept baselines for readonly property check changes
Copilot 22e0201
Fix regression: Keep CommonJS module.exports check before readonly check
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
testdata/baselines/reference/compiler/readonlyDefaultExport.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| b.ts(3,5): error TS2540: Cannot assign to 'a' because it is a read-only property. | ||
|
|
||
|
|
||
| ==== a.ts (0 errors) ==== | ||
| const foo = { | ||
| a: 1 | ||
| } | ||
|
|
||
| export default foo as Readonly<typeof foo> | ||
|
|
||
| ==== b.ts (1 errors) ==== | ||
| import foo from './a' | ||
|
|
||
| foo.a = 2 | ||
| ~ | ||
| !!! error TS2540: Cannot assign to 'a' because it is a read-only property. | ||
|
|
30 changes: 30 additions & 0 deletions
30
testdata/baselines/reference/compiler/readonlyDefaultExport.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||||||
| //// [tests/cases/compiler/readonlyDefaultExport.ts] //// | ||||||||||
|
|
||||||||||
| //// [a.ts] | ||||||||||
| const foo = { | ||||||||||
| a: 1 | ||||||||||
| } | ||||||||||
|
|
||||||||||
| export default foo as Readonly<typeof foo> | ||||||||||
jakebailey marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
|
||||||||||
|
Comment on lines
+8
to
+9
|
||||||||||
| export default foo as Readonly<typeof foo> | |
| const readonlyFoo = foo as Readonly<typeof foo>; | |
| export default readonlyFoo; |
24 changes: 24 additions & 0 deletions
24
testdata/baselines/reference/compiler/readonlyDefaultExport.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //// [tests/cases/compiler/readonlyDefaultExport.ts] //// | ||
|
|
||
| === a.ts === | ||
| const foo = { | ||
| >foo : Symbol(foo, Decl(a.ts, 0, 5)) | ||
|
|
||
| a: 1 | ||
| >a : Symbol(a, Decl(a.ts, 0, 13)) | ||
| } | ||
|
|
||
| export default foo as Readonly<typeof foo> | ||
| >foo : Symbol(foo, Decl(a.ts, 0, 5)) | ||
| >Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --)) | ||
| >foo : Symbol(foo, Decl(a.ts, 0, 5)) | ||
|
|
||
| === b.ts === | ||
| import foo from './a' | ||
| >foo : Symbol(foo, Decl(b.ts, 0, 6)) | ||
|
|
||
| foo.a = 2 | ||
| >foo.a : Symbol(a, Decl(a.ts, 0, 13)) | ||
| >foo : Symbol(foo, Decl(b.ts, 0, 6)) | ||
| >a : Symbol(a, Decl(a.ts, 0, 13)) | ||
|
|
28 changes: 28 additions & 0 deletions
28
testdata/baselines/reference/compiler/readonlyDefaultExport.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| //// [tests/cases/compiler/readonlyDefaultExport.ts] //// | ||
|
|
||
| === a.ts === | ||
| const foo = { | ||
| >foo : { a: number; } | ||
| >{ a: 1} : { a: number; } | ||
|
|
||
| a: 1 | ||
| >a : number | ||
| >1 : 1 | ||
| } | ||
|
|
||
| export default foo as Readonly<typeof foo> | ||
| >foo as Readonly<typeof foo> : Readonly<{ a: number; }> | ||
| >foo : { a: number; } | ||
| >foo : { a: number; } | ||
|
|
||
| === b.ts === | ||
| import foo from './a' | ||
| >foo : Readonly<{ a: number; }> | ||
|
|
||
| foo.a = 2 | ||
| >foo.a = 2 : 2 | ||
| >foo.a : any | ||
| >foo : Readonly<{ a: number; }> | ||
| >a : any | ||
| >2 : 2 | ||
|
|
14 changes: 14 additions & 0 deletions
14
testdata/baselines/reference/conformance/typedefModuleExportsIndirect1.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| typedefModuleExportsIndirect1.js(3,8): error TS2540: Cannot assign to 'exports' because it is a read-only property. | ||
|
|
||
|
|
||
| ==== typedefModuleExportsIndirect1.js (1 errors) ==== | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const dummy = 0; | ||
| module.exports = dummy; | ||
| ~~~~~~~ | ||
| !!! error TS2540: Cannot assign to 'exports' because it is a read-only property. | ||
| ==== use.js (0 errors) ==== | ||
| /** @typedef {import('./typedefModuleExportsIndirect1').C} C */ | ||
| /** @type {C} */ | ||
| var c | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
testdata/baselines/reference/conformance/typedefModuleExportsIndirect2.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| typedefModuleExportsIndirect2.js(3,8): error TS2540: Cannot assign to 'exports' because it is a read-only property. | ||
|
|
||
|
|
||
| ==== typedefModuleExportsIndirect2.js (1 errors) ==== | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const f = function() {}; | ||
| module.exports = f; | ||
| ~~~~~~~ | ||
| !!! error TS2540: Cannot assign to 'exports' because it is a read-only property. | ||
jakebailey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ==== use.js (0 errors) ==== | ||
| /** @typedef {import('./typedefModuleExportsIndirect2').C} C */ | ||
| /** @type {C} */ | ||
| var c | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
testdata/baselines/reference/conformance/typedefModuleExportsIndirect3.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| typedefModuleExportsIndirect3.js(3,8): error TS2540: Cannot assign to 'exports' because it is a read-only property. | ||
|
|
||
|
|
||
| ==== typedefModuleExportsIndirect3.js (1 errors) ==== | ||
| /** @typedef {{ a: 1, m: 1 }} C */ | ||
| const o = {}; | ||
| module.exports = o; | ||
| ~~~~~~~ | ||
| !!! error TS2540: Cannot assign to 'exports' because it is a read-only property. | ||
| ==== use.js (0 errors) ==== | ||
| /** @typedef {import('./typedefModuleExportsIndirect3').C} C */ | ||
| /** @type {C} */ | ||
| var c | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.