Skip to content

Bug: TSImportType's option object always has key with #11114

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

Open
4 tasks done
overlookmotel opened this issue Apr 28, 2025 · 3 comments · May be fixed by #11115
Open
4 tasks done

Bug: TSImportType's option object always has key with #11114

overlookmotel opened this issue Apr 28, 2025 · 3 comments · May be fixed by #11115
Labels
accepting prs Go ahead, send a pull request that resolves this issue AST PRs and Issues about the AST structure bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@overlookmotel
Copy link

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Relevant Package

typescript-estree

Playground Link

https://typescript-eslint.io/play/#ts=5.8.2&showAST=es&fileType=.tsx&code=C4TwDgpgBAKlC8UCWBbMB7ATsAFAIhTwBooBvKAdyWAAsAuMqPTCAZ3QBsBXYJdAOwC0KdABMIeBnlQZseKAF9FASgDcAKFCQoAVQTI0WXAWKMAhq1YRsDcszacefISPGSmMo-KUK16oA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

type T = import("m", { with: { "resolution-mode": "import" } });
type U = import("m", { assert: { "resolution-mode": "import" } });

ESLint Config

tsconfig

Expected Result

Both statements include a TSImportType with an options property containing an ObjectExpression. Both ObjectExpressions have a single Property.

The key of Property in 1st statement is with.

The key of Property in 2nd statement is also with! I'd have expected it to be assert.

Actual Result

(see above)

Additional Info

I think this is a bug. But apologies if this is a stupid query. I don't know TypeScript at all well.

I notice that TypeScript's AST doesn't seem to differentiate between the two either, so maybe it's not possible for TS-ESLint to?

Versions

package version
@typescript-eslint/parser 8.31.1
@overlookmotel overlookmotel added bug Something isn't working triage Waiting for team members to take a look labels Apr 28, 2025
@overlookmotel
Copy link
Author

Actually, there is a way to differentiate between the two - the range on the Identifier for the property key has length 6 when it's assert, vs 4 when it's with.

That's a pretty odd workaround, but as far as I'm aware, with and assert are the only legal values in this position, so it should be accurate.

graphite-app bot pushed a commit to oxc-project/oxc that referenced this issue Apr 28, 2025
…` in TS-ESTree AST (#10681)

TS-ESLint parser replaces a property of `options` called `assert` with one called `with`.

typescript-eslint/typescript-eslint#11114

This looks like it's an error on their side, but in the meantime replicate this behavior.
@bradzacher
Copy link
Member

the reason this happens is because TS doesn't differentiate between the two and our code just blindly grabs the token without checking its text -- which is why the range is correct but the name is not.

const withToken = findNextToken(openBraceToken, node, this.ast)!;
const withTokenRange = getRange(withToken, this.ast);
options = this.createNode<TSESTree.ObjectExpression>(node, {
type: AST_NODE_TYPES.ObjectExpression,
range: [openBraceToken.getStart(this.ast), closeBraceToken.end],
properties: [
this.createNode<TSESTree.Property>(node, {
type: AST_NODE_TYPES.Property,
range: [withTokenRange[0], node.attributes.end],
computed: false,
key: this.createNode<TSESTree.Identifier>(node, {
type: AST_NODE_TYPES.Identifier,
range: withTokenRange,
decorators: [],
name: 'with',
optional: false,
typeAnnotation: undefined,
}),

@bradzacher bradzacher added package: typescript-estree Issues related to @typescript-eslint/typescript-estree AST PRs and Issues about the AST structure accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Apr 28, 2025
@overlookmotel
Copy link
Author

overlookmotel commented Apr 29, 2025

Thanks very much for coming back so swiftly, and pointing me to the right place. PR to fix: #11115.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue AST PRs and Issues about the AST structure bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
2 participants