-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Limit when we allow nested unique symbols to be serialized #40886
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
weswigham
merged 1 commit into
microsoft:master
from
weswigham:error-on-anonymous-type-with-nonlocal-unique-symbol
Oct 5, 2020
Merged
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions
11
...s/baselines/reference/declarationEmitExpressionWithNonlocalPrivateUniqueSymbol.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,11 @@ | ||
tests/cases/compiler/b.ts(2,14): error TS2527: The inferred type of 'A1' references an inaccessible 'unique symbol' type. A type annotation is necessary. | ||
|
||
|
||
==== tests/cases/compiler/a.ts (0 errors) ==== | ||
type AX = { readonly A: unique symbol }; | ||
export const A: AX = 0 as any; | ||
==== tests/cases/compiler/b.ts (1 errors) ==== | ||
import { A } from './a'; | ||
export const A1 = A; | ||
~~ | ||
!!! error TS2527: The inferred type of 'A1' references an inaccessible 'unique symbol' type. A type annotation is necessary. |
28 changes: 28 additions & 0 deletions
28
tests/baselines/reference/declarationEmitExpressionWithNonlocalPrivateUniqueSymbol.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,28 @@ | ||
//// [tests/cases/compiler/declarationEmitExpressionWithNonlocalPrivateUniqueSymbol.ts] //// | ||
|
||
//// [a.ts] | ||
type AX = { readonly A: unique symbol }; | ||
export const A: AX = 0 as any; | ||
//// [b.ts] | ||
import { A } from './a'; | ||
export const A1 = A; | ||
|
||
//// [a.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.A = void 0; | ||
exports.A = 0; | ||
//// [b.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.A1 = void 0; | ||
var a_1 = require("./a"); | ||
exports.A1 = a_1.A; | ||
|
||
|
||
//// [a.d.ts] | ||
declare type AX = { | ||
readonly A: unique symbol; | ||
}; | ||
export declare const A: AX; | ||
export {}; |
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/declarationEmitExpressionWithNonlocalPrivateUniqueSymbol.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,17 @@ | ||
=== tests/cases/compiler/a.ts === | ||
type AX = { readonly A: unique symbol }; | ||
>AX : Symbol(AX, Decl(a.ts, 0, 0)) | ||
>A : Symbol(A, Decl(a.ts, 0, 11)) | ||
|
||
export const A: AX = 0 as any; | ||
>A : Symbol(A, Decl(a.ts, 1, 12)) | ||
>AX : Symbol(AX, Decl(a.ts, 0, 0)) | ||
|
||
=== tests/cases/compiler/b.ts === | ||
import { A } from './a'; | ||
>A : Symbol(A, Decl(b.ts, 0, 8)) | ||
|
||
export const A1 = A; | ||
>A1 : Symbol(A1, Decl(b.ts, 1, 12)) | ||
>A : Symbol(A, Decl(b.ts, 0, 8)) | ||
|
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/declarationEmitExpressionWithNonlocalPrivateUniqueSymbol.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,18 @@ | ||
=== tests/cases/compiler/a.ts === | ||
type AX = { readonly A: unique symbol }; | ||
>AX : AX | ||
>A : unique symbol | ||
|
||
export const A: AX = 0 as any; | ||
>A : AX | ||
>0 as any : any | ||
>0 : 0 | ||
|
||
=== tests/cases/compiler/b.ts === | ||
import { A } from './a'; | ||
>A : { readonly A: unique symbol; } | ||
|
||
export const A1 = A; | ||
>A1 : { readonly A: unique symbol; } | ||
>A : { readonly A: unique symbol; } | ||
|
7 changes: 7 additions & 0 deletions
7
tests/cases/compiler/declarationEmitExpressionWithNonlocalPrivateUniqueSymbol.ts
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,7 @@ | ||
// @declaration: true | ||
// @filename: a.ts | ||
type AX = { readonly A: unique symbol }; | ||
export const A: AX = 0 as any; | ||
// @filename: b.ts | ||
import { A } from './a'; | ||
export const A1 = A; |
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.
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.
Wait, why couldn’t it just serialize as
typeof A
(ortypeof import('./a').A
if the import gets erased) here?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.
I said as why in the issue, but I'll restate it here: because that could only work for specific patterns of assignments, and while we may carve out syntactic patterns for checking JS, we do not for TS. So because it doesn't generalize beyond
var x = entity.name
assignments to all assignments, it doesn't make sense to do, really.