Repository navigation
noImplicitAny checks don't work for a setter parameter of Object.defineProperty #8410
Description
Activity
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
TypedPropertyDescriptorinstead ofPropertyDescriptor, that will make your setter argument inferred from declaration, so it will be{}and notany, which would be closer to an error. but that would be a breaking change.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
- addedSuggestionAn idea for TypeScriptAn idea for TypeScriptIn DiscussionNot yet reached consensusNot yet reached consensus
on May 1, 2016 falsandtru commented
on May 1, 2016 ContributorAuthorMore actionsrelated: #8373
- addedDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScript
on May 2, 2016 I don't think they are actually related. It is being properly contextually typed as any. What I think Mohamed Hegazy (@mhegazy) is suggesting is that it might be worth this being implemented in
lib.d.tsin the future, as it stands at the moment it will always be non-implicitanybecause of the contextual typing: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.
- addedWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bugand removedIn DiscussionNot yet reached consensusNot yet reached consensus
on May 16, 2016 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.
- locked and limited conversation to collaborators
on Jun 19, 2018
TypeScript Version:
master
Code
Expected behavior:
error
Actual behavior:
pass