Skip to content
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

octal escapes are not handled correctly in string literal types #24209

Closed
ajafff opened this issue May 17, 2018 · 4 comments
Closed

octal escapes are not handled correctly in string literal types #24209

ajafff opened this issue May 17, 2018 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@ajafff
Copy link
Contributor

ajafff commented May 17, 2018

TypeScript Version: 2.9.0-rc

Search Terms: type octal

Code

const a: '\1' = '1'; // 'a' is of type '1' and contains '1'
const b: '\1' = '\1'; // 'b' is of type '1', but contains '\u0001'
const c = '\1'; // same as 'b'

Expected behavior:

Octal escapes in string literals are handled correctly.

For LiteralTypeNodes I would probably prefer a grammar error, but type inference also needs to handle octal escapes.

Actual behavior:

Octal escapes are ignored when converting a StringLiteral to a LiteralType.

Playground Link: https://agentcooper.github.io/typescript-play/?target=5#code/MYewdgzgLgBAhgLhgcgDoEZkwLwswbhgHoiU4sBLCGEAMxigE8AHAUzyzjABMZQwocCpA4AoftBgAjJGkw4UGZIRIoplanQYt2yTABppAV1j9Bw6miMAGW5nHhJwBXOXFSEOAFt2cS+qA

Related Issues:

@ajafff
Copy link
Contributor Author

ajafff commented May 17, 2018

It seems like this is not specific to literal types. This is caused by incorrect parsing of octal escape sequences in every StringLiteral.

@DanielRosenwasser
Copy link
Member

Duplicate of #396.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label May 17, 2018
@ajafff
Copy link
Contributor Author

ajafff commented May 17, 2018

#396 is about making octal escape sequences an error. Only #396 (comment) mentions some difficulties with the scanner / parser.

However, I'm ok with closing this as duplicate. I hope nobody uses octal escape sequences anymore so the type checking inconsistencies are not a problem in real world code.

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants