Skip to content
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

Object spread operation typings are divorced from resultant runtime values. #50185

Closed
jasa-blad opened this issue Aug 4, 2022 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@jasa-blad
Copy link

Bug Report

🔎 Search Terms

spread object

🕗 Version & Regression Information

v4.7.4 v4.8.0-beta

  • This is a crash
  • This changed between versions ______ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play?ts=4.7.4#code/MYewdgzgLgsAUAAhAIwFYFNhQIzwLwDe8CAFugDbkgBcARAOogBO5AJrfAL4ICGECoSFADc8MXEHRiKDFgBM+IojKUatALI8mEDnG58B4aKLjiAZgFcwWAJbgEAZQAOTdD1YAeAIIAaAEIAfAAUPNS+yNR+AJRKCK5QFkxgsQgAdOk8PsRp6chZiJxc4vCSsIgOFQ74zq7uQTKYOD4N8lEmAPTtCFAkNvwAnhSs-GDoAG7oTKnFcJ0I9CQ8UN1k3f1O6BD90OgAtis2YADWEPBzNW6evoEIeAEIXgBkfjNzC0txVlA2u+jtteQbFB+ghxjxyBYlptujQzl0Lu5vP57ncEAB5XZApEII7ofogMwIQLPIA

Playground link with relevant code

💻 Code

const
 object1
={
 hello:"World"
} as const;


const
 object2
={
 hello:"Mars"
} as const;


function Spread<A extends object, B extends object>(a:A,b:B){
 return{
  ...a,
  ...b,
 }
}


const
 SSSS
=Spread(object1,object2);
// this yelds never.


// What the typesystem thinks
// Spread<A,B> => A&B


// What runtime/reality evaluates to:
// Spread<A,B> => Omit<A, keyof B>&B

🙁 Actual behavior

The resultant type of the spread operation did not model that which is happening in runtime.

🙂 Expected behavior

The type system is grounded and models that which is happening in runtime.

@jasa-blad
Copy link
Author

Its hard to implement infered types when the type system gets in the way, regardless of the robustness of being able to declare type dependencies in consuming functions or classes.

@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Aug 4, 2022

Duplicate #10727. Lacking a specific type operator to represent spread, ... uses intersection as the next-closest thing when one of the operands is a type parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants