Skip to content

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

Description

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:

Activity

  1. ajafff commented on May 17, 2018

    @ajafff
    ContributorAuthor

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

  2. DanielRosenwasser commented on May 17, 2018

    @DanielRosenwasser
    Member

    Duplicate of #396.

  3. ajafff commented on May 17, 2018

    @ajafff
    ContributorAuthor

    #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.

  4. typescript-bot commented on Jun 2, 2018

    @typescript-bot
    Contributor

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

  5. locked and limited conversation to collaborators on Aug 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions