Skip to content

No compile error when generic type inferred to be {} #756

Closed
@duncanbrown

Description

@duncanbrown

I think the following should result in an error, but it passes the type checker:

function foo<T>(getT: () => T, setT: (t: T) => void) { }

function getString() {
    return 'a';
}

function setNum(n: number) { }

foo(getString, setNum);

Hovering over the call to foo in VS or the Playground shows that T has been inferred to be of type {}, but since {} isn't of type number, doesn't that make setNum an invalid argument to be passing in?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions