ds300 / ds300/react-native-typescript-transformer

SyntaxError: Unexpected token for string literal types with back ticks

Open
#83 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
656
Forks
47
PR merge metrics
No merged PRs in 30d

Description

Hello,

I'm converting our build process which used to leverage `tsc --watch` having our `index.js` entrypoint import from `build\app.js` to use react-native-typescript-transformer.

Declaring a string literal type which has backticks in it does not work.

So, this used to compile & run fine:
```type a = `test`;```

Error Output:
error: bundling failed: SyntaxError: .../file.ts: Unexpected token
at _class.raise (../node_modules/@babel/parser/lib/index.js:3906:15)
at _class.unexpected (../node_modules/@babel/parser/lib/index.js:5235:16)
at _class.tsParseNonArrayType (../node_modules/@babel/parser/lib/index.js:9046:18)
at _class.tsParseArrayTypeOrHigher (../node_modules/@babel/parser/lib/index.js:9050:23)
at _class.tsParseTypeOperatorOrHigher (../node_modules/@babel/parser/lib/index.js:9094:122)
at _class.tsParseUnionOrIntersectionType (../node_modules/@babel/parser/lib/index.js:9099:18)
at _class.tsParseIntersectionTypeOrHigher (../node_modules/@babel/parser/lib/index.js:9117:19)
at _class.tsParseUnionOrIntersectionType (../node_modules/@babel/parser/lib/index.js:9099:18)
at _class.tsParseUnionTypeOrHigher (../node_modules/@babel/parser/lib/index.js:9121:19)
at _class.tsParseNonConditionalType (../node_modules/@babel/parser/lib/index.js:9256:19)

We can get past this by converting our string literal to not use the backticks and get by the error fine. So the following works:
```type a = 'test'```

Any thoughts on what's happening here?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.