TypeScript Version: 2.4.1
Code
promise.catch(error => {
error.foo.bar // no error. `error` type is `any`
})
In this example, there is no type checking on property lookups on error because error has type any.
I understand it is not possible to know the true type of a the rejected promise value/reason (see #5413). However, I would question whether we could replace any with the empty object type {}.
This would mean the above example would throw a type error, which is desirable because it is safer. The user may widen choose the type of error using user-defined type guards.
Has this been considered at all? I am also curious if the same idea could be applied to other uses of any in libs.
TypeScript Version: 2.4.1
Code
In this example, there is no type checking on property lookups on
errorbecauseerrorhas typeany.I understand it is not possible to know the true type of a the rejected promise value/reason (see #5413). However, I would question whether we could replace
anywith the empty object type{}.This would mean the above example would throw a type error, which is desirable because it is safer. The user may widen choose the type of
errorusing user-defined type guards.Has this been considered at all? I am also curious if the same idea could be applied to other uses of
anyin libs.