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
object spread generic intersect
https://www.typescriptlang.org/play?ts=5.3.0-dev.20231005#code/GYVwdgxgLglg9mABAWwIYGsCmB1APAeUUwA8pMwATAZ0QG9FUAuBsAT0QF8AaRAIQD4AFHGb4eqAEzNeiAJR0AUIkQAnTFBAqk9AHR6445pJ4cA3ArMKFEBFSiIA7ogC8KDDkH0mdRACNmAIwMNDZgdpzcPhDMEsGIoeEcsubWtnAANpg66XAA5oIOOqg6vi7OrgHJQA
function makeW<O extends { a: any }, B>(o: O, a2: B ) { return { ...o, a: a2, }; }; const w = makeW({ a: { b: 1 as const }}, { c: 2 as const }); console.log(w.a.b === 1);
Return type of makeW is resolved/inferred as O & { a: B } which is wrong.
makeW
O & { a: B }
the returned value { ...o, a: a2 } overrides any o.a.
{ ...o, a: a2 }
o.a
type of w is Omit<O, "a"> & { a: B }.
w
Omit<O, "a"> & { a: B }
Explicit typing works, but should be needed.
function makeW<O extends { a: any }, B>(o: O, a2: B ): Omit<O, "a"> & { a: B } { return { ...o, a: a2 }; }; const w = makeW({ a: { b: 1 as const }}, { c: 2 as const }); console.log(w.a.b === 1); // type error, no `b`.
The text was updated successfully, but these errors were encountered:
Duplicate #10727
Sorry, something went wrong.
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
No branches or pull requests
🔎 Search Terms
object spread generic intersect
🕗 Version & Regression Information
This is a crash:This changed between versions ______ and _______I was unable to test this on prior versions because _______⏯ Playground Link
https://www.typescriptlang.org/play?ts=5.3.0-dev.20231005#code/GYVwdgxgLglg9mABAWwIYGsCmB1APAeUUwA8pMwATAZ0QG9FUAuBsAT0QF8AaRAIQD4AFHGb4eqAEzNeiAJR0AUIkQAnTFBAqk9AHR6445pJ4cA3ArMKFEBFSiIA7ogC8KDDkH0mdRACNmAIwMNDZgdpzcPhDMEsGIoeEcsubWtnAANpg66XAA5oIOOqg6vi7OrgHJQA
💻 Code
🙁 Actual behavior
Return type of
makeW
is resolved/inferred asO & { a: B }
which is wrong.the returned value
{ ...o, a: a2 }
overrides anyo.a
.🙂 Expected behavior
type of
w
isOmit<O, "a"> & { a: B }
.Additional information about the issue
Explicit typing works, but should be needed.
The text was updated successfully, but these errors were encountered: