Skip to content

Identifiers with Astral Unicode characters are unsupported #31963

@Alhadis

Description

@Alhadis

TypeScript Version

3.5.1

Search Terms

utf8, unicode

Code

const 𝑚 = 4;
const 𝑀 = 5;
console.log(𝑀 + 𝑚); // 9

Expected behaviour

The above is legal JavaScript, so 9 should be printed to the console.

Actual behaviour

The TypeScript compiler goes completely apeshit:

(click to see warnings)
test.ts:1:7 - error TS1127: Invalid character.

1 const 𝑚 = 4;
        

test.ts:1:8 - error TS1127: Invalid character.

1 const 𝑚 = 4;
         

test.ts:1:10 - error TS1134: Variable declaration expected.

1 const 𝑚 = 4;
           ~

test.ts:1:12 - error TS1134: Variable declaration expected.

1 const 𝑚 = 4;
             ~

test.ts:2:7 - error TS1127: Invalid character.

2 const 𝑀 = 5;
        

test.ts:2:8 - error TS1127: Invalid character.

2 const 𝑀 = 5;
         

test.ts:2:10 - error TS1134: Variable declaration expected.

2 const 𝑀 = 5;
           ~

test.ts:2:12 - error TS1134: Variable declaration expected.

2 const 𝑀 = 5;
             ~

test.ts:3:13 - error TS1127: Invalid character.

3 console.log(𝑀 + 𝑚); // 9
              

test.ts:3:14 - error TS1127: Invalid character.

3 console.log(𝑀 + 𝑚); // 9
               

test.ts:3:18 - error TS1127: Invalid character.

3 console.log(𝑀 + 𝑚); // 9
                   

test.ts:3:19 - error TS1127: Invalid character.

3 console.log(𝑀 + 𝑚); // 9

... and generates obviously unusable JavaScript:

var ;
4;
var ;
5;
console.log(+); // 9

More info

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions