Skip to content

Spread operator cannot be typed with intersection type #57100

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

Closed
reverofevil opened this issue Jan 19, 2024 · 6 comments
Closed

Spread operator cannot be typed with intersection type #57100

reverofevil opened this issue Jan 19, 2024 · 6 comments
Labels
Duplicate An existing issue was already created

Comments

@reverofevil
Copy link

reverofevil commented Jan 19, 2024

πŸ”Ž Search Terms

intersection spread

πŸ•— Version & Regression Information

  • I was unable to test this on prior versions because there is no online bisect tool for that, and git clone of TS repo doesn't work on Windows

⏯ Playground Link

https://www.typescriptlang.org/play?#code/MYewdgzgLgBAtgUwE4HMEwLwwDwEEA0MAQgHwAUAhgFwwEwBGNRAlJiTGQN4B0vFhvbvQC+zANwAoCaEiwArphicAHjTKsM7AORbhkmdBgA3RSrUb2ABj3TwhgO6nVHCzChI5CG7dkxlixFQEMjlCQLQyI0J7ZmZuZXVJAHokv24oEAAZEHtkAGEKCHQASwgYMBBYChgAMzkwYChi8B8IEAAbBG52kBQyZXSsnPzC4NixIA

πŸ’» Code

const merge = <A, B>(a: A, b: B) => ({...a, ...b});

const u = {x: () => ''};
const v = {x: () => 0};
const w = {x: () => true};

const x = merge(u, merge(v, w)).x();
// x.toLowerCase is not a function
console.log(x.toLowerCase());

πŸ™ Actual behavior

TS doesn't see any kind of an issue with the code

πŸ™‚ Expected behavior

Property 'toLowerCase' does not exist on type 'boolean'

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 19, 2024
@RyanCavanaugh
Copy link
Member

#50185 (comment)

@reverofevil
Copy link
Author

@RyanCavanaugh It links a suggestion/feature request, and this one is surely a bug. Can we mark that one as bug, or unduplicate this one?

@RyanCavanaugh
Copy link
Member

Correctly representing this requires a new feature. Missing features aren't bugs - there's no straightforward way to just "fix" this without that feature.

@reverofevil
Copy link
Author

It doesn't, really. The type is Exclude<A, keyof B> & B, modulo other bugs in intersections' implementation.

@RyanCavanaugh
Copy link
Member

That doesn't correctly handle optional properties.

@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 22, 2024
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

3 participants