Skip to content

Incorrect variance in checking functions in jsx #25451

@goloveychuk

Description

@goloveychuk

TypeScript Version: 2.9.2, 3.0.0-dev.20180705

Search Terms:

Code

import * as React from 'react'

interface A {
    b: string
}

interface B extends A {
    c: string
}

interface Props {
    cb(val: A): void
}

const Comp: React.SFC<Props> = () => null

function cb(val: B) {
    console.log(val.c)
}

const a = <Comp cb={cb}/> // no error

let f: Props['cb'] 
let f2: (val: A) => void

f = cb // no error

f2 = cb // error

Expected behavior:
Errors in all places
Actual behavior:
No error in jsx and when using Props['cb']
Playground Link:

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions