You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot reference an object within one of its methods' default arguments #11628
letObj={get(){},set(value=Obj.get()){}};Obj.missing();// Obj is treated as `any`, so I don't get any error for the usage of the undefined method `missing`
Expected behavior:
I expect to get an error for the usage of the undefined method Obj.missing.
Actual behavior:
I don't get any, since if I use Obj within a default argument inside one of Obj's own methods the entire object type becomes any.
Ugly workaround:
let_self;letObj=_self={get(){},set(value=_self.get()){}};Obj.missing();// I get an error as expected
I expect to get an error for the usage of the undefined method Obj.missing.
you would under --noImplicitAny.
c:\ts>tsc --noImplicitAny a.ts
a.ts(1,5): error TS7022: 'Obj' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
a.ts(3,9): error TS7022: 'value' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
Why should I be forced to use --noImplicitAny or to write ugly workarounds when it seems clear to me that the problem is that TypeScript should be a little smarter about this particular case?
Maybe I'm wrong about it, but why should this behavior be considered the correct one?
Activity
mhegazy commentedon Oct 17, 2016
you would under
--noImplicitAny.fabiospampinato commentedon Oct 18, 2016
Why should I be forced to use
--noImplicitAnyor to write ugly workarounds when it seems clear to me that the problem is that TypeScript should be a little smarter about this particular case?Maybe I'm wrong about it, but why should this behavior be considered the correct one?