Skip to content

noImplicitAny reports incorrect error? #8546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
radu-b opened this issue May 10, 2016 · 1 comment
Closed

noImplicitAny reports incorrect error? #8546

radu-b opened this issue May 10, 2016 · 1 comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@radu-b
Copy link

radu-b commented May 10, 2016

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.

@mhegazy
Copy link
Contributor

mhegazy commented May 10, 2016

The compiler tries to figure out the return types of functions from the type of their return expressions. this can depend on figuring out other types. sometimes that could lead to cycles; the compiler breaks these by giving the type any. this can be solved by adding an explicit type annotation, something like render(): JSX.Element { .. }.

Please see my reply to a similar issue in #1146 (comment)

@mhegazy mhegazy closed this as completed Jun 7, 2016
@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jun 7, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

2 participants