Skip to content

noImplicitAny reports incorrect error? #8546

@radu-b

Description

@radu-b

TypeScript Version:

1.8.10

Code
This code uses the React type definitions via tsd install react-global

Unfortunately I could not reproduce the problem in a simpler setting, such as using a plain base class, without React and TSX.

class Control extends React.Component<any, any> {
    render() {
        return <button onClick={() => buttonClicked(Control)}>Button</button>;
    }
}

function buttonClicked(controlType: typeof React.Component) {
}

It is compiled using a tsconfig.json file:

{
    "compilerOptions": {
        "noImplicitAny": true,
        "jsx": "react"        
    }
}

Expected behavior:
No compile errors.

Actual behavior:
Error TS7023: 'render' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

The problem does not happen if the onClick callback is given through an intermediary variable, instead of being inlined.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions