Repository navigation
Fix #19666: Check for symbol types in template expressions #22251
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
Mohamed Hegazy (mhegazy)
merged 3 commits into
microsoft:master
from
jack-williams:jack-williams/no-implicit-symbol-to-string
Mar 30, 2018
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/noImplicitSymbolToString.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,32 @@ | ||
| tests/cases/compiler/noImplicitSymbolToString.ts(6,30): error TS2352: Type 'symbol' cannot be converted to type 'string'. | ||
| tests/cases/compiler/noImplicitSymbolToString.ts(7,30): error TS2469: The '+' operator cannot be applied to type 'symbol'. | ||
| tests/cases/compiler/noImplicitSymbolToString.ts(8,8): error TS2469: The '+=' operator cannot be applied to type 'symbol'. | ||
| tests/cases/compiler/noImplicitSymbolToString.ts(13,47): error TS2352: Type 'symbol' cannot be converted to type 'string'. | ||
| tests/cases/compiler/noImplicitSymbolToString.ts(13,90): error TS2352: Type 'symbol' cannot be converted to type 'string'. | ||
|
|
||
|
|
||
| ==== tests/cases/compiler/noImplicitSymbolToString.ts (5 errors) ==== | ||
| // Fix #19666 | ||
|
|
||
| let symbol!: symbol; | ||
| let str = "hello "; | ||
|
|
||
| const templateStr = `hello ${symbol}`; | ||
| ~~~~~~ | ||
| !!! error TS2352: Type 'symbol' cannot be converted to type 'string'. | ||
| const appendStr = "hello " + symbol; | ||
| ~~~~~~ | ||
| !!! error TS2469: The '+' operator cannot be applied to type 'symbol'. | ||
| str += symbol; | ||
| ~~~~~~ | ||
| !!! error TS2469: The '+=' operator cannot be applied to type 'symbol'. | ||
|
|
||
| let symbolUnionNumber!: symbol | number; | ||
| let symbolUnionString!: symbol | string; | ||
|
|
||
| const templateStrUnion = `union with number ${symbolUnionNumber} and union with string ${symbolUnionString}`; | ||
| ~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2352: Type 'symbol' cannot be converted to type 'string'. | ||
| ~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2352: Type 'symbol' cannot be converted to type 'string'. | ||
|
|
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,26 @@ | ||
| //// [noImplicitSymbolToString.ts] | ||
| // Fix #19666 | ||
|
|
||
| let symbol!: symbol; | ||
| let str = "hello "; | ||
|
|
||
| const templateStr = `hello ${symbol}`; | ||
| const appendStr = "hello " + symbol; | ||
| str += symbol; | ||
|
|
||
| let symbolUnionNumber!: symbol | number; | ||
| let symbolUnionString!: symbol | string; | ||
|
|
||
| const templateStrUnion = `union with number ${symbolUnionNumber} and union with string ${symbolUnionString}`; | ||
|
|
||
|
|
||
| //// [noImplicitSymbolToString.js] | ||
| // Fix #19666 | ||
| var symbol; | ||
| var str = "hello "; | ||
| var templateStr = "hello " + symbol; | ||
| var appendStr = "hello " + symbol; | ||
| str += symbol; | ||
| var symbolUnionNumber; | ||
| var symbolUnionString; | ||
| var templateStrUnion = "union with number " + symbolUnionNumber + " and union with string " + symbolUnionString; |
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/noImplicitSymbolToString.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,32 @@ | ||
| === tests/cases/compiler/noImplicitSymbolToString.ts === | ||
| // Fix #19666 | ||
|
|
||
| let symbol!: symbol; | ||
| >symbol : Symbol(symbol, Decl(noImplicitSymbolToString.ts, 2, 3)) | ||
|
|
||
| let str = "hello "; | ||
| >str : Symbol(str, Decl(noImplicitSymbolToString.ts, 3, 3)) | ||
|
|
||
| const templateStr = `hello ${symbol}`; | ||
| >templateStr : Symbol(templateStr, Decl(noImplicitSymbolToString.ts, 5, 5)) | ||
| >symbol : Symbol(symbol, Decl(noImplicitSymbolToString.ts, 2, 3)) | ||
|
|
||
| const appendStr = "hello " + symbol; | ||
| >appendStr : Symbol(appendStr, Decl(noImplicitSymbolToString.ts, 6, 5)) | ||
| >symbol : Symbol(symbol, Decl(noImplicitSymbolToString.ts, 2, 3)) | ||
|
|
||
| str += symbol; | ||
| >str : Symbol(str, Decl(noImplicitSymbolToString.ts, 3, 3)) | ||
| >symbol : Symbol(symbol, Decl(noImplicitSymbolToString.ts, 2, 3)) | ||
|
|
||
| let symbolUnionNumber!: symbol | number; | ||
| >symbolUnionNumber : Symbol(symbolUnionNumber, Decl(noImplicitSymbolToString.ts, 9, 3)) | ||
|
|
||
| let symbolUnionString!: symbol | string; | ||
| >symbolUnionString : Symbol(symbolUnionString, Decl(noImplicitSymbolToString.ts, 10, 3)) | ||
|
|
||
| const templateStrUnion = `union with number ${symbolUnionNumber} and union with string ${symbolUnionString}`; | ||
| >templateStrUnion : Symbol(templateStrUnion, Decl(noImplicitSymbolToString.ts, 12, 5)) | ||
| >symbolUnionNumber : Symbol(symbolUnionNumber, Decl(noImplicitSymbolToString.ts, 9, 3)) | ||
| >symbolUnionString : Symbol(symbolUnionString, Decl(noImplicitSymbolToString.ts, 10, 3)) | ||
|
|
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,38 @@ | ||
| === tests/cases/compiler/noImplicitSymbolToString.ts === | ||
| // Fix #19666 | ||
|
|
||
| let symbol!: symbol; | ||
| >symbol : symbol | ||
|
|
||
| let str = "hello "; | ||
| >str : string | ||
| >"hello " : "hello " | ||
|
|
||
| const templateStr = `hello ${symbol}`; | ||
| >templateStr : string | ||
| >`hello ${symbol}` : string | ||
| >symbol : symbol | ||
|
|
||
| const appendStr = "hello " + symbol; | ||
| >appendStr : string | ||
| >"hello " + symbol : string | ||
| >"hello " : "hello " | ||
| >symbol : symbol | ||
|
|
||
| str += symbol; | ||
| >str += symbol : string | ||
| >str : string | ||
| >symbol : symbol | ||
|
|
||
| let symbolUnionNumber!: symbol | number; | ||
| >symbolUnionNumber : number | symbol | ||
|
|
||
| let symbolUnionString!: symbol | string; | ||
| >symbolUnionString : string | symbol | ||
|
|
||
| const templateStrUnion = `union with number ${symbolUnionNumber} and union with string ${symbolUnionString}`; | ||
| >templateStrUnion : string | ||
| >`union with number ${symbolUnionNumber} and union with string ${symbolUnionString}` : string | ||
| >symbolUnionNumber : number | symbol | ||
| >symbolUnionString : string | symbol | ||
|
|
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/taggedTemplateStringWithSymbolExpression01.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,17 @@ | ||
| //// [taggedTemplateStringWithSymbolExpression01.ts] | ||
| // taggedTemplateStringWithSymbolExpression01.ts | ||
|
|
||
| declare function foo(template: any, val: symbol): number; | ||
| let x!: symbol; | ||
|
|
||
| let result: number = foo`${x}`; | ||
|
|
||
|
|
||
| //// [taggedTemplateStringWithSymbolExpression01.js] | ||
| // taggedTemplateStringWithSymbolExpression01.ts | ||
| var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { | ||
| if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } | ||
| return cooked; | ||
| }; | ||
| var x; | ||
| var result = foo(__makeTemplateObject(["", ""], ["", ""]), x); |
16 changes: 16 additions & 0 deletions
16
tests/baselines/reference/taggedTemplateStringWithSymbolExpression01.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,16 @@ | ||
| === tests/cases/compiler/taggedTemplateStringWithSymbolExpression01.ts === | ||
| // taggedTemplateStringWithSymbolExpression01.ts | ||
|
|
||
| declare function foo(template: any, val: symbol): number; | ||
| >foo : Symbol(foo, Decl(taggedTemplateStringWithSymbolExpression01.ts, 0, 0)) | ||
| >template : Symbol(template, Decl(taggedTemplateStringWithSymbolExpression01.ts, 2, 21)) | ||
| >val : Symbol(val, Decl(taggedTemplateStringWithSymbolExpression01.ts, 2, 35)) | ||
|
|
||
| let x!: symbol; | ||
| >x : Symbol(x, Decl(taggedTemplateStringWithSymbolExpression01.ts, 3, 3)) | ||
|
|
||
| let result: number = foo`${x}`; | ||
| >result : Symbol(result, Decl(taggedTemplateStringWithSymbolExpression01.ts, 5, 3)) | ||
| >foo : Symbol(foo, Decl(taggedTemplateStringWithSymbolExpression01.ts, 0, 0)) | ||
| >x : Symbol(x, Decl(taggedTemplateStringWithSymbolExpression01.ts, 3, 3)) | ||
|
|
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/taggedTemplateStringWithSymbolExpression01.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/taggedTemplateStringWithSymbolExpression01.ts === | ||
| // taggedTemplateStringWithSymbolExpression01.ts | ||
|
|
||
| declare function foo(template: any, val: symbol): number; | ||
| >foo : (template: any, val: symbol) => number | ||
| >template : any | ||
| >val : symbol | ||
|
|
||
| let x!: symbol; | ||
| >x : symbol | ||
|
|
||
| let result: number = foo`${x}`; | ||
| >result : number | ||
| >foo`${x}` : number | ||
| >foo : (template: any, val: symbol) => number | ||
| >`${x}` : string | ||
| >x : symbol | ||
|
|
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,13 @@ | ||
| // Fix #19666 | ||
|
|
||
| let symbol!: symbol; | ||
| let str = "hello "; | ||
|
|
||
| const templateStr = `hello ${symbol}`; | ||
| const appendStr = "hello " + symbol; | ||
| str += symbol; | ||
|
|
||
| let symbolUnionNumber!: symbol | number; | ||
| let symbolUnionString!: symbol | string; | ||
|
|
||
| const templateStrUnion = `union with number ${symbolUnionNumber} and union with string ${symbolUnionString}`; | ||
6 changes: 6 additions & 0 deletions
6
tests/cases/compiler/taggedTemplateStringWithSymbolExpression01.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,6 @@ | ||
| // taggedTemplateStringWithSymbolExpression01.ts | ||
|
|
||
| declare function foo(template: any, val: symbol): number; | ||
| let x!: symbol; | ||
|
|
||
| let result: number = foo`${x}`; |
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.
I'm not huge on the test file name here, but it's fine. Can you add a case where you have a value of type
symbol | number(or something in a union)?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.
Will do. I'm open to changing the name. Perhaps templateStringWithSymbolExpressionErrors.ts ?