-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Add typed overloads to Object.create
#39882
Comments
#3865 predates this one but was closed. I'm not sure why it was closed, but it might provide useful information.
I'd like to contribute my own use case (Stack Overflow link): "I'm working on some legacy code I didn't write, trying to refactor it to typescript. ... writing the type definition by hand ... is quite painstaking, especially when the |
@ExE-Boss I'm probably doing something wrong, but the overload isn't giving me the type I would expect when I use it like this. |
Surely this kind of use case is pretty common? declare const arr: {
keyLike: string,
prop1: string,
prop2: number,
}[]
declare const arbitraryString: string
const lookupObj = Object.assign(
Object.create(null),
Object.fromEntries(arr.map(({ keyLike, ...rest }) => [keyLike, rest])),
)
const val = lookupObj[arbitraryString]
// expected type: `{ prop1: string, prop2: number } | undefined`
// actual type: `any` I guess typing Notably, simply defining Edit: I know generally |
Search Terms
Suggestion
Change the signatures of
Object.create
to:Use Cases
Getting correct types in code that does:
Examples
Checklist
My suggestion meets these guidelines:
strictBindCallApply
, or just done in a separatelib
file.Relevant issues
The text was updated successfully, but these errors were encountered: