Skip to content

Compiler Doesn't Enforce Generic Return Type on Callable Signature #33908

Closed
@berwyn

Description

@berwyn

TypeScript Version: 3.5.3 - 3.7.0-dev.20191009

Search Terms: return type enforcement generic callable signature

Code

interface Foo {
  value: number
}

type SomeCallType<T> = () => T;

const example: SomeCallType<Foo> = () => ({ value: 1, bar: 2 })

Expected behavior:
The above sample should not compile and instead emit ts(2322) because bar is not a valid property for Foo

Actual behavior:
The code will in fact compile and emit as if nothing were the matter.

Playground Link: here

Related Issues:
These may be related, given that they involve other cases where return types don't appear to be correctly enforced on callable signatures:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fix AvailableA PR has been opened for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions