-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Incorrect hover information when initializing a union-typed const
with never
#59626
Comments
The hover information is correct. This is subject to control flow analysis - despite the hover at the declaration (where you see the declared type) the actual type of the variable is an "assignment reduced type". This makes it possible to write code like this: declare function takeString(str: string): void
type A = string | number
const test: A = 'foo'
takeString(test) // ok! The type of There are 2 options/questions here that could be asked:
|
I would vote for (1). If This will make debugging easier. For example, the current behavior confused the guy behind vue-tsc, who should have fair enough experience with TypeScript: vuejs/language-tools#4682 For (3), that shouldn't be a problem since the actual inferred type is still |
(1) I wasn't talking about what gets displayed in the tooltip but rather about what's the actual type coming out of this assignment. The issue with the confusing tooltips is a known DX issue, I can't find the reference issue for it right now though. |
I don't see something that's more consistent than what we're already doing. Let's say you had this declare const foo: "foo" | "bar";
switch (foo) {
case "foo":
case "bar":
break;
default:
type T = typeof foo;
foo satisfies never;
} If |
Yes, the hover info is fine - it's consistent with how it works everywhere. I just wonder if regular declare const nothing: never;
const strOrNum: string | number = nothing;
strOrNum
// ^? const strOrNum: never
const str: string = nothing;
str
// ^? const str: string |
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
"hover information", "union"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.6.0-beta#code/PTAEAkHsDcFMCdQwaABgM0pVoDOALSAd1zQGNIA7XAF1E0gC48b4BLSgc1AB9RKArgFsARglQAoCtToNmACkGiUfWuy4BKUAF5+AgDb6AhBIkgIyRJbQAxLDgLFSqGgE8ADrFB3IO-rDh4STdPbyw-ENhIdHosCSA
π» Code
π Actual behavior
Hover over
foo
showsconst foo: string | number
π Expected behavior
Hover over
foo
should shownever
, the same astype Foo
.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: