-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
💻
- Would you like to work on a fix?
How are you using Babel?
Programmatic API (babel.transform
, babel.parse
)
Input code
console.log(t.TSTypeOperator(t.TSTypeQuery(t.Identifier('x')), 'keyof'));
Configuration file name
No response
Configuration
No response
Current and expected behavior
Current behaviour: operator
field is null
Expected behaviour: operator
field is keyof
I want to create node like this:
type ODirection = typeof ODirection[keyof typeof ODirection];
But have only:
type ODirection = typeof ODirection[null typeof ODirection];
When using:
const id = Identifier('ODirection');
const type = TSTypeAliasDeclaration(id, null, TSIndexedAccessType(TSTypeQuery(id), TSTypeOperator(TSTypeQuery(id), 'keyof')))
Environment
latest babel
Possible solution
Add handling of operator
to TSTypeQuery
.
Looks like the problem in https://github.com/babel/babel/blob/main/packages/babel-types/src/builders/generated/index.ts#L2254:
It should be https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/ast-spec/src/type/TSTypeOperator/spec.ts: