From 10bc4cbbb53417f6eb99c53a4cf81fabc560025d Mon Sep 17 00:00:00 2001 From: Philipp Zins Date: Thu, 23 Nov 2017 10:30:13 +0100 Subject: [PATCH 1/2] allow returning an array of jsx elements --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a2b0d4b823e3f..079312b1a02af 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15208,7 +15208,7 @@ namespace ts { if (!deferredJsxStatelessElementType) { const jsxElementType = getJsxGlobalElementType(); if (jsxElementType) { - deferredJsxStatelessElementType = getUnionType([jsxElementType, nullType]); + deferredJsxStatelessElementType = getUnionType([createArrayType(jsxElementType), jsxElementType, nullType]); } } return deferredJsxStatelessElementType; From 5ae54a5a767137a9c1995c9bbc27333aac548d3b Mon Sep 17 00:00:00 2001 From: Philipp Zins Date: Thu, 23 Nov 2017 13:24:47 +0100 Subject: [PATCH 2/2] added tests --- .../baselines/reference/tsxSfcReturnArray.js | 24 ++++++++++++ .../reference/tsxSfcReturnArray.symbols | 28 ++++++++++++++ .../reference/tsxSfcReturnArray.types | 37 +++++++++++++++++++ .../conformance/jsx/tsxSfcReturnArray.tsx | 17 +++++++++ 4 files changed, 106 insertions(+) create mode 100644 tests/baselines/reference/tsxSfcReturnArray.js create mode 100644 tests/baselines/reference/tsxSfcReturnArray.symbols create mode 100644 tests/baselines/reference/tsxSfcReturnArray.types create mode 100644 tests/cases/conformance/jsx/tsxSfcReturnArray.tsx diff --git a/tests/baselines/reference/tsxSfcReturnArray.js b/tests/baselines/reference/tsxSfcReturnArray.js new file mode 100644 index 0000000000000..4d7f114962110 --- /dev/null +++ b/tests/baselines/reference/tsxSfcReturnArray.js @@ -0,0 +1,24 @@ +//// [file.tsx] +import React = require('react'); + +const Foo = (props: any) => [, ]; + +function Greet(x: { name?: string }) { + return [, ]; +} + +const foo = ; +const G = ; + + +//// [file.jsx] +define(["require", "exports", "react"], function (require, exports, React) { + "use strict"; + exports.__esModule = true; + var Foo = function (props) { return [, ]; }; + function Greet(x) { + return [, ]; + } + var foo = ; + var G = ; +}); diff --git a/tests/baselines/reference/tsxSfcReturnArray.symbols b/tests/baselines/reference/tsxSfcReturnArray.symbols new file mode 100644 index 0000000000000..4cf2d23cb5af3 --- /dev/null +++ b/tests/baselines/reference/tsxSfcReturnArray.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/jsx/file.tsx === +import React = require('react'); +>React : Symbol(React, Decl(file.tsx, 0, 0)) + +const Foo = (props: any) => [, ]; +>Foo : Symbol(Foo, Decl(file.tsx, 2, 5)) +>props : Symbol(props, Decl(file.tsx, 2, 13)) +>span : Symbol(JSX.IntrinsicElements.span, Decl(react.d.ts, 2461, 51)) +>span : Symbol(JSX.IntrinsicElements.span, Decl(react.d.ts, 2461, 51)) + +function Greet(x: { name?: string }) { +>Greet : Symbol(Greet, Decl(file.tsx, 2, 49)) +>x : Symbol(x, Decl(file.tsx, 4, 15)) +>name : Symbol(name, Decl(file.tsx, 4, 19)) + + return [, ]; +>span : Symbol(JSX.IntrinsicElements.span, Decl(react.d.ts, 2461, 51)) +>span : Symbol(JSX.IntrinsicElements.span, Decl(react.d.ts, 2461, 51)) +} + +const foo = ; +>foo : Symbol(foo, Decl(file.tsx, 8, 5)) +>Foo : Symbol(Foo, Decl(file.tsx, 2, 5)) + +const G = ; +>G : Symbol(G, Decl(file.tsx, 9, 5)) +>Greet : Symbol(Greet, Decl(file.tsx, 2, 49)) + diff --git a/tests/baselines/reference/tsxSfcReturnArray.types b/tests/baselines/reference/tsxSfcReturnArray.types new file mode 100644 index 0000000000000..ee6fa3f735535 --- /dev/null +++ b/tests/baselines/reference/tsxSfcReturnArray.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/jsx/file.tsx === +import React = require('react'); +>React : typeof React + +const Foo = (props: any) => [, ]; +>Foo : (props: any) => JSX.Element[] +>(props: any) => [, ] : (props: any) => JSX.Element[] +>props : any +>[, ] : JSX.Element[] +> : JSX.Element +>span : any +> : JSX.Element +>span : any + +function Greet(x: { name?: string }) { +>Greet : (x: { name?: string; }) => JSX.Element[] +>x : { name?: string; } +>name : string + + return [, ]; +>[, ] : JSX.Element[] +> : JSX.Element +>span : any +> : JSX.Element +>span : any +} + +const foo = ; +>foo : JSX.Element +> : JSX.Element +>Foo : (props: any) => JSX.Element[] + +const G = ; +>G : JSX.Element +> : JSX.Element +>Greet : (x: { name?: string; }) => JSX.Element[] + diff --git a/tests/cases/conformance/jsx/tsxSfcReturnArray.tsx b/tests/cases/conformance/jsx/tsxSfcReturnArray.tsx new file mode 100644 index 0000000000000..9b79a009ad993 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxSfcReturnArray.tsx @@ -0,0 +1,17 @@ +// @filename: file.tsx +// @jsx: preserve +// @module: amd +// @noLib: true +// @skipLibCheck: true +// @libFiles: react.d.ts,lib.d.ts + +import React = require('react'); + +const Foo = (props: any) => [, ]; + +function Greet(x: { name?: string }) { + return [, ]; +} + +const foo = ; +const G = ;