[React] Include ElementChildrenAttribute for 2.3 #16327
Conversation
This is a new feature in 2.3 as TypeScript will be able to check JSX.children
|
types/react/index.d.ts to authors (@pspeter3 @vsiao @johnnyreilly @bbenezech @pzavolinsky @digiguru @ericanderson AssureSign (account can't be detected) Microsoft (account can't be detected)). Could you review this PR? Checklist
|
|
@yui can you rebase against master |
|
@yuit this change broke previously-valid TSX code and I'm not sure what the right way is to fix it. I've uploaded a repro to demonstrate the issue here: https://github.com/shiftkey/react-types-children |
|
@shiftkey Thanks for trying this out!..... I will put simplified version of the code here for reference. Original Code import * as React from 'react'
interface IRowProps {
readonly children?: ReadonlyArray<JSX.Element>;
}
export class Row extends React.Component<IRowProps, void> {
public render() {
return (
<div>
{this.props.children}
</div>
)
}
}
let row = <Row>
<span>things go here</span>
</Row>Error Explaination Fix interface IRowProps {
readonly children?: ReadonlyArray<JSX.Element> | JSX.Element;
} |
…eactToIncludeChildren [React] Include ElementChildrenAttribute for 2.3
|
@yuit So, If I have something like: How I can type force I've been trying to figure it out, but without success, thanks in advance. |
|
@AlgusDark that's unfortunately not supported. You can constrain children only to be |
This is a new feature in 2.3 as TypeScript will be able to check JSX.children
This is the update need for this feature to work microsoft/TypeScript#15160
Please fill in this template.
npm run lint package-name(ortscif notslint.jsonis present).Select one of these and delete the others:
If adding a new definition:
dts-gen --dt, not by basing it on an existing project.tslint.jsonshould be present, andtsconfig.jsonshould havenoImplicitAny,noImplicitThis, andstrictNullChecksset totrue.If changing an existing definition:
tslint.jsoncontaining{ "extends": "dslint/dt.json" }.If removing a declaration:
notNeededPackages.json.