-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
lib.es2022: hasOwn
appears to be defined on Object
prototype rather than on constructor
#48206
Comments
This is an intended UX trade-off in JS files. Since often you'll have untyped variables, we show method help based on name-matching; this way if you're looking for help for a common method name, it shows up even without matching type information. For more precise behavior, you can turn on See also #33565 |
Thanks for the reply! I'm seeing this in a TypeScript file in a TypeScript React project when trying to upgrade from 4.3.5 to 4.6.2. Does the same behavior apply? Let me get a more specific example of the issue I'm running into, one sec. |
I ran into this issue because I was trying to upgrade the project from 4.3.5 to 4.6.2. The project has some object types with e.g. interface SomeComponentProps {
requiredProp: boolean
hasOwn?: boolean;
} Using those types started failing to typecheck after the upgrade since TypeScript. For example: const SomeComponent: React.FC<SomeComponentProps> = () => {}
return <SomeComponent requiredProp />
// TS2322: Type '{ requiredProp: boolean }' is not assignable to type 'SomeComponentProps'.
Types of property 'hasOwn' are incompatible.
Type '(o: object, v: PropertyKey) => boolean' is not assignable to type 'boolean'. |
No, you're totally right, this is just the lib being wrong. Misread what you were getting at. |
No problem! I should've provided the more specific error case up front. |
I'm happy to make a PR with test cases for the fix, though it might take me a bit longer since I haven't contributed to TypeScript before. If you'd like to fix this internally that's fine by me. |
I'll put up a PR. Thanks for the report π |
Component commits: d1b063e Move `hasOwn` from Object instance to Object constructor Fixes microsoft#48206
Do you know if or when this might land in a patch version? |
We'll be doing a patch release in the next week or two (just waiting to see if other patchworthy things appear first) |
Bug Report
π Search Terms
hasOwn, Object.hasOwn, es2022, prototype, lib.es2022.object.d.ts
π Version & Regression Information
Appears to be introduced by #46291
β― Playground Link
Doesn't appear to reproduce on Playground or Bug Workbench, reproduces in VS Code 1.66.0-insider (e80a0ca648fe9bef07070e4f7fb04e67f2243252) running TypeScript 4.6.2.
π» Code
π Actual behavior
I ran into this issue because I was trying to upgrade the project from 4.3.5 to 4.6.2. The project has some object types with
hasOwn
as a boolean property.π Expected behavior
hasOwn
should be a method of theObject
constructor (Object.hasOwn
), not the prototype (foo.hasOwn
).The text was updated successfully, but these errors were encountered: