-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Helper messages and autocomplete broken for inferred function props #22636
Comments
It looks like we aren't treating JSX constructors as well as we treat regular calls when it comes to quick info. import * as React from "React";
interface FooProps<T> {
value: T;
callback: (input: T) => string;
}
class Foo<T> extends React.Component<FooProps<T>> { }
function foo<T>(_obj: { value: T, callback: (input: T) => string }) { }
// Hover over callback shows (JSX Attribute) callback: (test: T) => any
// Hover over test shows (parameter) test: T
<Foo value={0} callback={test => test.toFixed()} />;
// Hover over callback shows `(property) callback: (input: number) => string`
// Hover over test shows (parameter) test: number
foo({ value: 0, callback: test => test.toFixed() });
class C<T> {
constructor(_o: { value: T, callback: (input: T) => string }) {}
}
// Same as function call
new C({ value: 0, callback: test => test.toFixed() }); |
I know you guys are very busy, but do you think there's a chance that this could be fixed in 2.8? |
I am afraid it is too late for including anything in 2.8 at the moment
we intend the whole thing to work in 2.9 end to end. |
I understand, thanks anyway, I am already quite happy that it is shipping so soon! Great Work! |
I was curious about this so I saw if I could figure out how to write a failing test. I've done so, but I’m not sure if it's the right approach or not. Feel free to use it or not. I’d potentially be interested in trying to work on this, but I don’t have to—I was just exploring for my own education. andrewbranch@75812b3 |
Reproduces on 2.8.0-dev.20180315
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
without errors, as the compilers actually knows that test is a string.
and you cannot write
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.
The text was updated successfully, but these errors were encountered: