Microsoft/TypeScript
Ver no GitHubCertain conditional types allow unsound assignments
Open
#55.733 aberto em 13 de set. de 2023
BugCursed?Domain: Conditional TypesHelp Wanted
Métricas do repositório
- Stars
- (48.455 stars)
- Métricas de merge de PR
- (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)
Description
🔎 Search Terms
"conditional type" generic assignment
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about conditional types
⏯ Playground Link
💻 Code
type Box<T> = { value: T }
type UnboxInner<T> = T extends Box<infer R> ? UnboxInner<R> : { unboxed: T }
type Unbox<T> = UnboxInner<T>['unboxed']
declare function unbox<T>(x: T): Unbox<T>
function example<T>(x: T) {
let a = unbox(x)
a = 'this should be an error'
}
🙁 Actual behavior
In example we can assign arbitrary values to a, even though it's typed as Unbox<T>.
🙂 Expected behavior
Attempting to assign invalid values to a (just about anything, since its type depends on a type parameter) should cause a type error.
Additional information about the issue
These issues may possibly be related:
- #52021
- #35533
cc @webstrand