Skip to content

Can't implement interface by throwing error #16874

Closed
@ghost

Description

TypeScript Version: nightly (2.5.0-dev.20170629)

Code

interface I { m(): number; }
const o: I = { m() { throw new Error("not implemented"); } }

Expected behavior:

No error.

Actual behavior:

Type '() => void' is not assignable to type '() => number'.

The same problem occurs inside a class. Manually annotating m(): number fixes the problem, but shouldn't we get that from the contextual type anyway?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions