Parse and check type arguments on JSX opening and self-closing tags#22415
Parse and check type arguments on JSX opening and self-closing tags#22415weswigham merged 2 commits intomicrosoft:masterfrom
Conversation
This handles support for microsoft/TypeScript#22415
src/compiler/checker.ts
Outdated
| min = Math.min(min, getMinTypeArgumentCount(sig.typeParameters)); | ||
| max = Math.max(max, length(sig.typeParameters)); | ||
| } | ||
| const paramCount = min < max ? min + "-" + max : min; |
There was a problem hiding this comment.
I would find min === max ? min : min + "-" + max clearer
src/compiler/checker.ts
Outdated
| } | ||
|
|
||
| function getTypeArgumentArityError(node: Node, signatures: Signature[], typeArguments: NodeArray<TypeNode>) { | ||
| let min = Number.POSITIVE_INFINITY; |
There was a problem hiding this comment.
Not sure why the original author didn't just use Infinity / -Infinity ?
RyanCavanaugh
left a comment
There was a problem hiding this comment.
I have nitty comments in moved code that can be ignored 👍
|
This is great! Is there a related issue on Babel? What is the process for ensuring they stay up to date? |
|
I don't think we have a formal process right now, but pinging @Andy-MS seems like a decent way to check. 😝 |
|
@weswigham Really great this finally made it into the language! Question: When tsconfig is set to |
|
It aught to be. If not, it's a bug. |
|
Is there any sense of in what release this will land? |
|
2.9 which will be released inside two months, given our bimonthly release cadence 😄 |
|
It seems that one has to explicitly specify the type, as oppose to that the compiler can infer the type from the value. What I mean is that in JSX, say I have the component below when I use MyComp, in the code below, specify the type number, otherwise the val variable will not have type of number. However, If I omit specifying the type number, the val variable will be type of {}. This seems to be a bug, because compare to Generics in regular class, like below., the type of number does not have to be explicitly specified. |
|
@marty-wang IIUC, I think what you're seeing is #22636 |
|
@andrewbranch yes, it is the same issue. In #22636 @mhegazy seems saying it would be addressed in 2.9. However, at least it is not yet in 2.9.0-dev.20180503. |
|
#23492 has yet to be merged |
|
@weswigham sweet! thanks! |
|
Question, What would be best way to pass a generic type to a child component? |
|
What you have there aught to be correct. |
|
@weswigham i was getting a |
|
Oh i guess i should of mentioned that List accepts a generic type |
|
You need to constrained your |
|
is there a non-jsx equivalent for this? e.g. given this usage w/ jsx <MyGenericComponent<SomeType> {...props} />what is the equivalent using createElement(StringInput, props)
// [ts] Type '{}' is not assignable to type 'SomeType'. |
|
I believe the first generic parameter of createElement<SomeType>(MyGenericComponent, props) |
|
The type signature of function createElement<P>(
type: SFC<P> | ComponentClass<P> | string,
props?: Attributes & P | null,
...children: ReactNode[]): ReactElement<P>;so looks like the first parameter is Props |
Allows, eg,
in
.tsxfiles.Fixes #6395.
Was there a list of things we were concerned wouldn't parse well? AFAIK, this is actually easy for us to unambiguously parse.