Microsoft/TypeScript
GitHub ã§èŠãInfer from usages should not widen literal types
Open
#52,991 opened on 2023幎2æ27æ¥
Domain: LS: RefactoringsExperience EnhancementHelp WantedSuggestion
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
Bug Report
ð Search Terms
string literal to string, infer type from usages, code fix, quickfix
⯠Playground Link
Playground link with relevant code
ð» Code
let a
a = "foo" as "foo" | "bar"
let b
b = getB()
checkB(b)
function checkB(toCheck: "foo" | "bar") {
}
function getB(): "foo" | "bar" {
return "foo"
}
ð Actual behavior
After running infer from usages quickfix, you get string type in a and b positions
ð Expected behavior
Should get inffered type "foo"
I think in case of as and satisfies clauses the type should be just copied literally?
As you can see from example this is common case for string enums, like when some function expects some string enum instead of just string, but this information gets lost