Cannot build identifier with TypeScript typeAnnotation
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 194
- Avg merge
- 22h 43m
- Merged PRs (30d)
- 10
Description
Trying to build an identifier with a TypeScript typeAnnotation throws an error because the expected type of the type annotation is `TypeAnnotation | null`, as defined in the flow defs https://github.com/benjamn/ast-types/blob/f4a7c6db8e0eed1f25971d4fcbb84843c83ad615/def/flow.js#L209-L210
For example, if I parse `const x: string` and look at the AST for the identifier I see
```
{
"type": "Identifier",
"name": "x",
"typeAnnotation": {
"type": "TSTypeAnnotation",
"typeAnnotation": {
"type": "TSStringKeyword"
}
}
}
```
But if I try to create this with a builder like so
```
astTypes.builders.identifier.from({ name: 'x', typeAnnotation: astTypes.builders.tsTypeAnnotation(astTypes.builders.tsStringKeyword()) })
```
I get the error
```
Uncaught Error: {typeAnnotation: [object Object], loc: null, type: TSTypeAnnotation, comments: null} does not match field "typeAnnotation": TypeAnnotation | null of type Identifier
```
I'll work on a fix for this and submit a PR
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with def/flow.js at the referenced lines, then compare the Identifier field definition with the TSTypeAnnotation produced by the shown builder call. Reproduce the failure using the provided const x: string example. Done means the TypeScript annotation can be supplied to the identifier builder without the type-mismatch error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100