-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Parse and check type arguments on JSX opening and self-closing tags #22415
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would find min === max ? min : min + "-" + max
clearer
src/compiler/checker.ts
Outdated
@@ -17337,6 +17380,17 @@ namespace ts { | |||
} | |||
} | |||
|
|||
function getTypeArgumentArityError(node: Node, signatures: Signature[], typeArguments: NodeArray<TypeNode>) { | |||
let min = Number.POSITIVE_INFINITY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why the original author didn't just use Infinity
/ -Infinity
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
Allows, eg,
in
.tsx
files.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.