Skip to content

Suggestion: stricter type for promise rejection value/reason #17440

@OliverJAsh

Description

@OliverJAsh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript vision

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions