|
| 1 | +//// [tests/cases/compiler/jsxFunctionTypeChildren.tsx] //// |
| 2 | + |
| 3 | +=== jsxFunctionTypeChildren.tsx === |
| 4 | +// https://github.com/microsoft/typescript-go/issues/2703 |
| 5 | + |
| 6 | +/// <reference path="react.d.ts" /> |
| 7 | + |
| 8 | +import * as React from 'react'; |
| 9 | +>React : Symbol(React, Decl(jsxFunctionTypeChildren.tsx, 4, 6)) |
| 10 | + |
| 11 | +type BaseProps = { locale: string }; |
| 12 | +>BaseProps : Symbol(BaseProps, Decl(jsxFunctionTypeChildren.tsx, 4, 31)) |
| 13 | +>locale : Symbol(locale, Decl(jsxFunctionTypeChildren.tsx, 6, 18)) |
| 14 | + |
| 15 | +type Props<T extends BaseProps> = { |
| 16 | +>Props : Symbol(Props, Decl(jsxFunctionTypeChildren.tsx, 6, 36)) |
| 17 | +>T : Symbol(T, Decl(jsxFunctionTypeChildren.tsx, 8, 11)) |
| 18 | +>BaseProps : Symbol(BaseProps, Decl(jsxFunctionTypeChildren.tsx, 4, 31)) |
| 19 | + |
| 20 | + children: (props: T) => React.ReactNode; |
| 21 | +>children : Symbol(children, Decl(jsxFunctionTypeChildren.tsx, 8, 35)) |
| 22 | +>props : Symbol(props, Decl(jsxFunctionTypeChildren.tsx, 9, 15)) |
| 23 | +>T : Symbol(T, Decl(jsxFunctionTypeChildren.tsx, 8, 11)) |
| 24 | +>React : Symbol(React, Decl(jsxFunctionTypeChildren.tsx, 4, 6)) |
| 25 | +>ReactNode : Symbol(React.ReactNode, Decl(react.d.ts, 91, 66)) |
| 26 | + |
| 27 | +} & T; |
| 28 | +>T : Symbol(T, Decl(jsxFunctionTypeChildren.tsx, 8, 11)) |
| 29 | + |
| 30 | +declare function Comp<T extends BaseProps>(props: Props<T>): JSX.Element; |
| 31 | +>Comp : Symbol(Comp, Decl(jsxFunctionTypeChildren.tsx, 10, 6)) |
| 32 | +>T : Symbol(T, Decl(jsxFunctionTypeChildren.tsx, 12, 22)) |
| 33 | +>BaseProps : Symbol(BaseProps, Decl(jsxFunctionTypeChildren.tsx, 4, 31)) |
| 34 | +>props : Symbol(props, Decl(jsxFunctionTypeChildren.tsx, 12, 43)) |
| 35 | +>Props : Symbol(Props, Decl(jsxFunctionTypeChildren.tsx, 6, 36)) |
| 36 | +>T : Symbol(T, Decl(jsxFunctionTypeChildren.tsx, 12, 22)) |
| 37 | +>JSX : Symbol(JSX, Decl(react.d.ts, 2355, 1)) |
| 38 | +>Element : Symbol(JSX.Element, Decl(react.d.ts, 2358, 27)) |
| 39 | + |
| 40 | +const bp: BaseProps = { locale: 'en' }; |
| 41 | +>bp : Symbol(bp, Decl(jsxFunctionTypeChildren.tsx, 14, 5)) |
| 42 | +>BaseProps : Symbol(BaseProps, Decl(jsxFunctionTypeChildren.tsx, 4, 31)) |
| 43 | +>locale : Symbol(locale, Decl(jsxFunctionTypeChildren.tsx, 14, 23)) |
| 44 | + |
| 45 | +// Error in ts-go: Type '(props: ...) => Element' is not assignable to |
| 46 | +// type '((props: ...) => ReactNode) & {}'. |
| 47 | +const el = <Comp {...bp}>{(props) => <div>{props.locale}</div>}</Comp>; |
| 48 | +>el : Symbol(el, Decl(jsxFunctionTypeChildren.tsx, 18, 5)) |
| 49 | +>Comp : Symbol(Comp, Decl(jsxFunctionTypeChildren.tsx, 10, 6)) |
| 50 | +>bp : Symbol(bp, Decl(jsxFunctionTypeChildren.tsx, 14, 5)) |
| 51 | +>props : Symbol(props, Decl(jsxFunctionTypeChildren.tsx, 18, 27)) |
| 52 | +>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2402, 45)) |
| 53 | +>props.locale : Symbol(locale, Decl(jsxFunctionTypeChildren.tsx, 6, 18)) |
| 54 | +>props : Symbol(props, Decl(jsxFunctionTypeChildren.tsx, 18, 27)) |
| 55 | +>locale : Symbol(locale, Decl(jsxFunctionTypeChildren.tsx, 6, 18)) |
| 56 | +>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2402, 45)) |
| 57 | +>Comp : Symbol(Comp, Decl(jsxFunctionTypeChildren.tsx, 10, 6)) |
| 58 | + |
| 59 | +// But the equivalent non-JSX call works fine: |
| 60 | +Comp({ ...bp, children: (props) => <div>{props.locale}</div> }); |
| 61 | +>Comp : Symbol(Comp, Decl(jsxFunctionTypeChildren.tsx, 10, 6)) |
| 62 | +>bp : Symbol(bp, Decl(jsxFunctionTypeChildren.tsx, 14, 5)) |
| 63 | +>children : Symbol(children, Decl(jsxFunctionTypeChildren.tsx, 21, 13)) |
| 64 | +>props : Symbol(props, Decl(jsxFunctionTypeChildren.tsx, 21, 25)) |
| 65 | +>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2402, 45)) |
| 66 | +>props.locale : Symbol(locale, Decl(jsxFunctionTypeChildren.tsx, 6, 18)) |
| 67 | +>props : Symbol(props, Decl(jsxFunctionTypeChildren.tsx, 21, 25)) |
| 68 | +>locale : Symbol(locale, Decl(jsxFunctionTypeChildren.tsx, 6, 18)) |
| 69 | +>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2402, 45)) |
| 70 | + |
0 commit comments