Skip to content

Conversation

@Andarist
Copy link
Contributor

fixes #61070

@jakebailey
Copy link
Member

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

@Andarist
Copy link
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
Member

@typescript-bot pack this

@typescript-bot
Copy link
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
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/[email protected]".;

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jan 30, 2025
@jakebailey
Copy link
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
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
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
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
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
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
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
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 🤷

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: Not started

Development

Successfully merging this pull request may close these issues.

Satisfies operator affects type inference for Symbol

4 participants