Skip to content

Walk all outer expression kinds before comitting to the return type of a symbol call#61071

Closed
Andarist wants to merge 5 commits intomicrosoft:mainfrom
Andarist:walk-all-outer-expressions-on-symbols
Closed

Walk all outer expression kinds before comitting to the return type of a symbol call#61071
Andarist wants to merge 5 commits intomicrosoft:mainfrom
Andarist:walk-all-outer-expressions-on-symbols

Conversation

@Andarist
Copy link
Copy Markdown
Contributor

fixes #61070

@jakebailey
Copy link
Copy Markdown
Member

Doesn't walkUpOuterExpressions do things other than satisfies and parens?

@Andarist
Copy link
Copy Markdown
Contributor Author

Doesn't walkUpOuterExpressions do things other than satisfies and parens?

Yes, I could control what it is supposed to handle with a bitmask but I decided that there is no harm to just use the default (All). Cause at the end of the day - what harm can be caused by it? One of the changes would be a changed error like:

-const bar = Symbol() as string; // Conversion of type 'symbol' to type 'string' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.(2352)
+const bar = Symbol() as string; // Conversion of type 'typeof bar' to type 'string' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.(2352)

@RyanCavanaugh
Copy link
Copy Markdown
Member

@typescript-bot pack this

@typescript-bot
Copy link
Copy Markdown
Collaborator

typescript-bot commented Jan 29, 2025

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
pack this ✅ Started ✅ Results

@typescript-bot
Copy link
Copy Markdown
Collaborator

typescript-bot commented Jan 29, 2025

Hey @RyanCavanaugh, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/164676/artifacts?artifactName=tgz&fileId=6AC0B4FA6225C679120D6D095ADE93E18CE2BB508C80F6B2148B4273E613A69102&fileName=/typescript-5.8.0-insiders.20250129.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@5.8.0-pr-61071-4".;

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jan 30, 2025
@jakebailey
Copy link
Copy Markdown
Member

Yes, I could control what it is supposed to handle with a bitmask but I decided that there is no harm to just use the default (All). Cause at the end of the day - what harm can be caused by it? One of the changes would be a changed error like:

Is there a test for this? I don't see it in the PR.

@Andarist
Copy link
Copy Markdown
Contributor Author

@jakebailey there is one now 😉


const testErrorMessage1 = Symbol() as string;
~~~~~~~~~~~~~~~~~~
!!! error TS2352: Conversion of type 'typeof testErrorMessage1' to type 'string' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this I'm not satisfied with (pun intended).

The complaint is about Symbol() as string, but the fact that it's in the context of a const declaration, its type now changes. It seems very odd to me that if I were to write something like (() => Symbol() as string)() that the message would be different.

I feel less weird about this error in the context of satisfies, maybe, but even that I think is strange to be talking about the actual declaration name....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I changed it to walkUpOuterExpressions(node, OuterExpressionKinds.Parentheses | OuterExpressionKinds.Satisfies) now

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks; can you also update the test with the other outer expression kinds, just to illustrate the differences? (Mainly just parens, satisfies, maybe !).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems very odd to me that if I were to write something like (() => Symbol() as string)() that the message would be different.

The type is already different between those 2 though:

const sym1 = Symbol();
const sym2 = (() => Symbol())();

I see your point though and I don't mind either solution ;p

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types are different, absolutely, I just view const foo = Symbol() to be a very specific syntactic construct, which this PR is saying should be extended to satisfies.

That being said, #61070 is closed as "not a defect", so I'm not sure if we're actually going to accept this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said, #61070 is closed as "not a defect", so I'm not sure if we're actually going to accept this?

That's fine. I opened this PR before that :P Feel free to close it. It's obviously not a real-world problem, but I sympathized with the OP's view that this is surprising in the context of the satisfies role. OTOH, Symbol() is just special so 🤷

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
@typescript-bot
Copy link
Copy Markdown
Collaborator

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Satisfies operator affects type inference for Symbol

4 participants