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

SyntaxError: Unexpected token for string literal types with back ticks #83

Open
jameslee523 opened this issue Oct 19, 2018 · 1 comment

Comments

@jameslee523
Copy link

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?

@johnlaine1
Copy link

Same here
type TYear = `${number}${number}${number}${number}`;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants