-
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
Strange behavior in function type inference #1926
Comments
We have two candidates for The only thing I can think of is that we could (could not would 😉) have a way to annotate that a use of a generic type parameter is not an inference site, e.g. you could say |
A bit sad :( I have everything working for jsx support in typescript but can't have type inference of jsx attribute because of that :p React component defintion is more or less something like that : interface Component <P> {
props: P;
}
interface ComponentClass<P> {
new(props: P): Component<P>;
prototype: { props: P };
}
interface HTMLAttributes {
....
}
function createElement<P>(type: ComponentClass<P>, props: P, ...rest: any[]): something;
function createElement(type: string, props: HTMLAttributes, ...rest: any[]): somethingElse; and for jsx: <MyComponent attribute='something' />
//is equivalent of:
createElement(MyComponent, { attribute: 'something' }); If someone think about a better way to define the types, or If you think about a way that I could have the correct inferred type in language service for the second argument, that could help ^_^. |
Just curious, is the idea that you desugar after parse-time into the call-form? |
@DanielRosenwasser not really, I tried to fully implements support of JSX in the checker, I consider Anyway for JSXElement : I tried at first to consider the
But it ended up to be very hackish since I had to create a lot of * fake node *, and since the type of |
While this is where you get into territory that is extremely inconsistent with the rest of the language, you might want to experiment with the semantics of type argument inference with respect to JSX tags. It probably won't be easy to get correct, but, well, it could be fun! |
Haha a little frightening :P, I think I'll start by finishing it correctly the way it is and perhaps I'll try that after ^^ thank you for your advice. |
Why not give a definition writer a possiblity to say which type is more specific?
I added the |
I found the behavior of the compiler here quite strange :
I'm not so sure, but I think this behavior is different of 1.0, sure
{}
is a super type of{ items: string }
but I doubt that's what the developer is excepting here.This is by the way preventing us from having correct inference for every factory like functions.
The text was updated successfully, but these errors were encountered: