-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Labels
area: typescriptgood first issueoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: types
Description
💻
- Would you like to work on a fix?
How are you using Babel?
Programmatic API (babel.transform, babel.parse)
Input code
See REPL: https://runkit.com/alexandre-cai/60a2ae9feaab4400130133c8
transform(`
type Test = 1 | -1;
`, {
parserOpts: {
plugins: ["typescript"],
},
plugins: [
({ types: t }) => ({
visitor: {
TSLiteralType(path) {
path.node = t.tsLiteralType(path.node.literal)
}
}
}),
],
})Configuration file name
No response
Configuration
No response
Current and expected behavior
Babel currently accepts UnaryExpression while parsing TSLiteralType, but can’t generate one. Output:
TypeError: unknown: Property literal of TSLiteralType expected node to be of a type
["NumericLiteral","StringLiteral","BooleanLiteral","BigIntLiteral"] but instead got "UnaryExpression"
Environment
- @babel/core: 7.14.2
Possible solution
https://github.com/babel/babel/blob/main/packages/babel-types/src/definitions/typescript.ts#L342
Add UnaryExpression.
Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: typescriptgood first issueoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: types