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

Why does Object.values return exact property types? #49921

Closed
iyegoroff opened this issue Jul 15, 2022 · 2 comments
Closed

Why does Object.values return exact property types? #49921

iyegoroff opened this issue Jul 15, 2022 · 2 comments

Comments

@iyegoroff
Copy link

lib Update Request

Configuration Check

My compilation target is esnext and my lib is es2017.

Missing / Incorrect Definition

Object.values returns exact property types instead of unknowns. This leads to errors in runtime.

Sample Code

type Foo = { x: string, y: string }
type Bar = { x: string, y: string; z: number }

// 'x' is considered a 'string' here
const processFoo = (foo: Foo) => Object.values(foo).map(x => x.endsWith('1'))

const bar: Bar = { x: '123', y: 'abc', z: 10 }

// throws "TypeError: x.endsWith is not a function. (In 'x.endsWith('1')', 'x.endsWith' is undefined)"
processFoo(bar)

playground link

Documentation Link

not related

@MartinJohns
Copy link
Contributor

See #38520.

@iyegoroff
Copy link
Author

Thanks for the quick reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants