We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
boolean invariant type parameter literal widen union
https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240824&ssl=14&ssc=130&pln=1&pc=1#code/PTAECEHsA8B4BUB8oAuBPADgU1ASwM54B2AbgIYBOuZRKxo8AsAFAvrYQwLIC8oA3i1CgA5lhQAuUAAoAlKB7J4AbiGh84qdPIAbAK5Yp8eYtAlIuACarmAXxstLWAMY7KOAGZ6izlLkhEoABGXEjaZPqGDLJSUHBIDszOAfh0QUQAjArBMNL8oBgUkBhSAAygtrLKoCCccPmFxVJEegC2QVgUFYgsyUSpwUQATLFcDUUloC3tnd3ZIdB5BRNlFVU1YADyANYsvSlpQVl8C0uNkx4RGmvVtXGw4005kDpYNN37-YcjdQ-LTyEXm9ArZeDlFo8LlccJVbmAAKIUIoUAA04L+5yklx011BU0gdDI+HwuBERDIQVeqEgv0hUkBr3eoJYQA
// Box<T> type is invariant in T type Box<T> = { get: () => T; set: (value: T) => void; }; declare function box<T>(value: T): Box<T>; const bn1 = box({ prop: 0 }); // Box<{ prop: number }> const bn2: Box<{ prop: number }> = box({ prop: 0 }); // Ok const bb1 = box({ prop: false }); // Box<{ prop: boolean }> const bb2: Box<{ prop: boolean }> = box({ prop: false }); // Error, box<{ prop: false }> not assignable to Box<{ prop: boolean }>
Error on bb2 is surprising and inconsistent with lack of error on bn2.
bb2
bn2
Expected the box(false) expression to have type Box<boolean> for both bb1 and bb2.
box(false)
Box<boolean>
bb1
This issue is a small variation of #48363 that was fixed by @ahejlsberg in #48380
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
π Search Terms
boolean invariant type parameter literal widen union
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240824&ssl=14&ssc=130&pln=1&pc=1#code/PTAECEHsA8B4BUB8oAuBPADgU1ASwM54B2AbgIYBOuZRKxo8AsAFAvrYQwLIC8oA3i1CgA5lhQAuUAAoAlKB7J4AbiGh84qdPIAbAK5Yp8eYtAlIuACarmAXxstLWAMY7KOAGZ6izlLkhEoABGXEjaZPqGDLJSUHBIDszOAfh0QUQAjArBMNL8oBgUkBhSAAygtrLKoCCccPmFxVJEegC2QVgUFYgsyUSpwUQATLFcDUUloC3tnd3ZIdB5BRNlFVU1YADyANYsvSlpQVl8C0uNkx4RGmvVtXGw4005kDpYNN37-YcjdQ-LTyEXm9ArZeDlFo8LlccJVbmAAKIUIoUAA04L+5yklx011BU0gdDI+HwuBERDIQVeqEgv0hUkBr3eoJYQA
π» Code
π Actual behavior
Error on
bb2
is surprising and inconsistent with lack of error onbn2
.π Expected behavior
Expected the
box(false)
expression to have typeBox<boolean>
for bothbb1
andbb2
.Additional information about the issue
This issue is a small variation of #48363 that was fixed by @ahejlsberg in #48380
The text was updated successfully, but these errors were encountered: