You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Control flow analysis for destructured rest element of discriminated union #46680
Yep, but par for the course for contexts like React where you might extract some props and forward the rest
importReactfrom'react'typeProps=|({as: "div"}&React.ComponentPropsWithRef<"div">)|({as: "span"}&React.ComponentPropsWithRef<"span">)functionComponent({ as, ...rest}: Props){if(as==='div'){return<div{...rest}/>}if(as==='span'){return<span{...rest}/>}// I think something like https://github.com/microsoft/TypeScript/issues/30581 would let us just do:// return <as {...rest} />}
Reacted by Steven Luscher, Sébastien Lorber, João Ferreira and Onyedikachi Ozoani
Can confirm this looks like something React devs do
Reacted by Sébastien Lorber, Mateus Vahl, Oleksandr Vinohradov, Sebastian Andil, jp2masa, Mike Holloway, Magoz, Fernando Greco, Steven Luscher, ortophius and 2 more
Reacted by lazytype, Tiago Alves, ortophius and nvmnghia
Activity
ahejlsberg commentedon Nov 4, 2021
Yeah, might be nice to support. Though it's an expensive way to do it as you're incurring an extra object allocation.
lazytype commentedon Nov 4, 2021
Yep, but par for the course for contexts like React where you might extract some props and forward the rest
andrewbranch commentedon Nov 4, 2021
Can confirm this looks like something React devs do
mhofman commentedon Jan 29, 2022
FYI, this is not only a React pattern, we would like to be able to write something like the following, based on #47190:
Output
Compiler Options
{ "compilerOptions": { "strict": true, "noImplicitAny": true, "strictNullChecks": true, "strictFunctionTypes": true, "strictPropertyInitialization": true, "strictBindCallApply": true, "noImplicitThis": true, "noImplicitReturns": true, "alwaysStrict": true, "esModuleInterop": true, "declaration": true, "experimentalDecorators": true, "emitDecoratorMetadata": true, "target": "ES2017", "module": "ESNext", "moduleResolution": "node" } }Playground Link: Provided
feat: v2.2 (#24)