Skip to content

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

Closed as not planned

Description

@jasa-blad

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.

Activity

  1. jasa-blad commented on Aug 4, 2022

    @jasa-blad
    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.

  2. RyanCavanaugh commented on Aug 4, 2022

    @RyanCavanaugh
    Member

    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.

  3. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions