-
-
Notifications
You must be signed in to change notification settings - Fork 780
fix(ast/estree): make TS-only fields optional in TS type defs #9846
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
fix(ast/estree): make TS-only fields optional in TS type defs #9846
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
@hi-ogawa I'm not a TypeScript user, and don't understand the TS syntax well. Can you please check this is correct? |
d3af692 to
ca81b25
Compare
9676cb8 to
3f858c4
Compare
ca81b25 to
6db8335
Compare
hi-ogawa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me 👍 This can potentially give inconvenience for users expecting typescript estree types, which has some fields strictly defined (for examples Class.implements array https://github.com/typescript-eslint/typescript-eslint/blob/3efd99e954d1749225d65b774cfb3650a54ff083/packages/ast-spec/src/base/ClassBase.ts#L50), but this typing is more correct as oxc types.
Additionally, I think we can add jsdoc on each ts-only fields, so it's easier to tell which fields can be assumed to be strictly defined when users are exclusively using astType: 'ts' parser.
Merge activity
|
When the source type is JS/JSX, `parseSync` returns an AST without any of the TS fields present (properties not present at all, not just defined as `undefined` / `null`). So to make our type defs match that AST (and also the TS AST which *does* have these fields), these fields need to be optional.
6db8335 to
7b711f0
Compare
|
Thanks for reviewing. We could also codegen 2 sets of types for JS-only and with-TS ASTs. As we're codegen-ing everything, that wouldn't be too much work. But I don't know if it'd be an improvement or not, because |
I don't think it's necessary right now, but just providing ts ast types can be useful without coupling with |

When the source type is JS/JSX,
parseSyncreturns an AST without any of the TS fields present (properties not present at all, not just defined asundefined/null). So to make our type defs match that AST (and also the TS AST which does have these fields), these fields need to be optional.