react-native-typescript-transformer
react-native-typescript-transformer copied to clipboard
SyntaxError: Unexpected token for string literal types with back ticks
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?
Same here type TYear = `${number}${number}${number}${number}`;