-
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
noImplicitAny checks don't work for a setter parameter of Object.defineProperty #8410
Comments
it gets a contextual type from the declaration, see https://github.com/Microsoft/TypeScript/blob/master/lib/lib.d.ts#L81. we could change the definition of defineProperty to use |
so just to be clear, the reported behavior is expected given the lib.d.ts definition. if there is anything to do is to change the definition in lib.d.ts |
related: #8373 |
I don't think they are actually related. It is being properly contextually typed as any. What I think @mhegazy is suggesting is that it might be worth this being implemented in interface PropertyDescriptor<T> {
configurable?: boolean;
enumerable?: boolean;
value?: T;
writable?: boolean;
get? (): T;
set? (v: T): void;
}
interface ObjectConstructor {
defineProperty<T>(o: any, p: string, attributes: PropertyDescriptor<T>): any;
} I suspect there are a few other places too that would need to be adjusted. |
As noted earlier, there is a context type passed through, and that suppresses the noImplicitAny errors. you can get a better behavior by defining an extra overload of define property as: interface ObjectConstructor {
defineProperty<T>(o: any, p: string, attributes: TypedPropertyDescriptor<T>): any;
} it is not clear there is much value in changing the lib.d.ts definitions for everybody though. |
TypeScript Version:
master
Code
Expected behavior:
error
Actual behavior:
pass
The text was updated successfully, but these errors were encountered: