Skip to content

Helper messages and autocomplete broken for inferred function props #22636

Closed
@MastroLindus

Description

@MastroLindus

Reproduces on 2.8.0-dev.20180315

interface FooProps<T> {
  callback: (input: T) => string;
  value: T;
}

class Foo<T> extends React.Component<FooProps<T>> {
  public render() {
    return "baz";
  }
}

const X = <Foo callback={test => test} value="asd"/>;

The bug is visible while using an IDE like visual code, but I expect the problem is in the language server, since from what I know it's the source for helper messages and the autocomplete functionality.

What happens is that the callback gets correctly inferred as (input: string) => string, in fact, you can write

callback={test => test.substring(0)}

without errors, as the compilers actually knows that test is a string.
and you cannot write

callback={test => 42}
or 
callback={test => test.methodNotOnString()}

However, if in visual code you hover over the callback, it shows as a function T => any, instead of string => string. The return value of substring will be shown as any.
Moreover autocomplete won't work correctly when trying to access a property of test.
It seems like the compiler does everything correctly in inferring the correct type, but the helper messages and autocomplete functions are instead unable to access the same inferred type.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: JSX/TSXRelates to the JSX parser and emitterFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions