Skip to content

Object spreading produces wrong type with non-literal keysΒ #56431

Open

Description

πŸ”Ž Search Terms

object spread, object rest, object spreading

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about object spreading

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.2.2#code/CYUwxgNghgTiAEYD2A7AzgF0QLngb3gG0BrEAT10xgEsUBzAXVxQFcBbAIxBngF8BYAFDJ0WKLgIlylDDXpN4VWnT7wAvPiEBIcfADkegDTaAdGbBDeQA

πŸ’» Code

declare const c: { [key: string]: number }
const a: { [key: string]: string } = {
	a: '',
	...c
}

πŸ™ Actual behavior

It allows numbers to be in the object, when they shouldn't be allowed.

πŸ™‚ Expected behavior

It shouldn't allow numbers.

Additional information about the issue

Because c has non-literal keys, in this case string, which could be any string, it doesn't care what's in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptExperimentation NeededSomeone needs to try this out to see what happens

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions