Uh oh!
There was an error while loading. Please reload this page.
Parse and check type arguments on JSX opening and self-closing tags - #22415
Conversation
This handles support for microsoft/TypeScript#22415
| 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
| } | ||
| 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 ?
Ryan Cavanaugh (RyanCavanaugh)
left a comment
There was a problem hiding this comment.
I have nitty comments in moved code that can be ignored 👍
Aaron Jensen (aaronjensen)
commented
Apr 3, 2018
This is great! Is there a related issue on Babel? What is the process for ensuring they stay up to date? |
Wesley Wigham (weswigham)
commented
Apr 3, 2018
I don't think we have a formal process right now, but pinging Andy (Andrewkraft) (@Andy-MS) seems like a decent way to check. 😝 |
Wesley Wigham (@weswigham) Really great this finally made it into the language! Question: When tsconfig is set to |
Wesley Wigham (weswigham)
commented
Apr 11, 2018
It aught to be. If not, it's a bug. |
Andrew Branch (andrewbranch)
commented
Apr 13, 2018
Is there any sense of in what release this will land? |
Wesley Wigham (weswigham)
commented
Apr 14, 2018
2.9 which will be released inside two months, given our bimonthly release cadence 😄 |
Mo (marty-wang)
commented
May 4, 2018
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. |
Andrew Branch (andrewbranch)
commented
May 4, 2018
Mo (@marty-wang) IIUC, I think what you're seeing is #22636 |
Andrew Branch (@andrewbranch) yes, it is the same issue. In #22636Mohamed Hegazy (@mhegazy) seems saying it would be addressed in 2.9. However, at least it is not yet in 2.9.0-dev.20180503. |
Wesley Wigham (weswigham)
commented
May 4, 2018
#23492 has yet to be merged |
Mo (marty-wang)
commented
May 4, 2018
Wesley Wigham (@weswigham) sweet! thanks! |
Question, What would be best way to pass a generic type to a child component? |
Wesley Wigham (weswigham)
commented
Jun 11, 2018
What you have there aught to be correct. |
Justin Bieber (jorySsense)
commented
Jun 11, 2018
Wesley Wigham (@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'. |
Nicky McCurdy (nickserv)
commented
Aug 16, 2018
I believe the first generic parameter of createElement<SomeType>(MyGenericComponent,props) |
The type signature of functioncreateElement<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.