Skip to content

Generic parameter types are incorrectly inferred as { } #26809

Closed
@2A5F

Description

@2A5F

TypeScript Version: 3.0.1, vscode 1.26.1

Search Terms:

Code

interface A<R> {
    a(): R
}

function some1<R>(a: A<R>): R {
    return null
}

function some2<R, D extends A<R>>(a: D): R {
    return null
}

let out1 = some1({
    a() {
        return 'asd'
    }
})

let out2 = some2({
    a() {
        return 'asd'
    }
})

Expected behavior: out1: string, out2: string

Actual behavior: out1: string, out2: {}

Playground Link

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions