From 19d05484d886da3401cf34b9ac108652ace67539 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 8 Nov 2016 09:34:23 -0800 Subject: [PATCH] Add tests for generic stateless function component --- ...ssFunctionComponentsWithTypeArguments1.tsx | 45 +++++++++++++++++++ ...ssFunctionComponentsWithTypeArguments2.tsx | 27 +++++++++++ ...ssFunctionComponentsWithTypeArguments3.tsx | 29 ++++++++++++ ...ssFunctionComponentsWithTypeArguments4.tsx | 17 +++++++ 4 files changed, 118 insertions(+) create mode 100644 tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments1.tsx create mode 100644 tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments2.tsx create mode 100644 tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments3.tsx create mode 100644 tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments4.tsx diff --git a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments1.tsx b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments1.tsx new file mode 100644 index 00000000000..3cae8471229 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments1.tsx @@ -0,0 +1,45 @@ +// @filename: file.tsx +// @jsx: preserve +// @module: amd +// @noLib: true +// @libFiles: react.d.ts,lib.d.ts + +import React = require('react') + + +declare function ComponentWithTwoAttributes(l: {key1: K, value: V}): JSX.Element; + +// OK +function Baz(key1: T, value: U) { + let a0 = + let a1 = +} + +// OK +declare function Component(l: U): JSX.Element; +function createComponent(arg:T) { + let a1 = ; + let a2 = ; +} + +declare function ComponentSpecific(l: {prop: U}): JSX.Element; +declare function ComponentSpecific1(l: {prop: U, "ignore-prop": number}): JSX.Element; + +// OK +function Bar(arg: T) { + let a1 = ; // U is number + let a2 = ; // U is number + let a3 = ; // U is "hello" +} + +declare function Link(l: {func: (arg: U)=>void}): JSX.Element; + +// OK +function createLink(func: (a: number)=>void) { + let o = +} + +function createLink1(func: (a: number)=>boolean) { + let o = +} + diff --git a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments2.tsx b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments2.tsx new file mode 100644 index 00000000000..e264ffde2ff --- /dev/null +++ b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments2.tsx @@ -0,0 +1,27 @@ +// @filename: file.tsx +// @jsx: preserve +// @module: amd +// @noLib: true +// @libFiles: react.d.ts,lib.d.ts + +import React = require('react') + +declare function ComponentSpecific1(l: {prop: U, "ignore-prop": string}): JSX.Element; +declare function ComponentSpecific2(l: {prop: U}): JSX.Element; + +// Error +function Bar(arg: T) { + let a1 = ; + } + +// Error +function Baz(arg: T) { + let a0 = +} + +declare function Link(l: {func: (arg: U)=>void}): JSX.Element; + +// Error +function createLink(func: (a: number, b: string)=>void) { + let o = +} \ No newline at end of file diff --git a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments3.tsx b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments3.tsx new file mode 100644 index 00000000000..68285c450c0 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments3.tsx @@ -0,0 +1,29 @@ +// @filename: file.tsx +// @jsx: preserve +// @module: amd +// @noLib: true +// @libFiles: react.d.ts,lib.d.ts + +import React = require('react') + +declare function OverloadComponent(): JSX.Element; +declare function OverloadComponent(attr: {b: U, a?: string, "ignore-prop": boolean}): JSX.Element; +declare function OverloadComponent(attr: {b: U, a: T}): JSX.Element; + +// OK +function Baz(arg1: T, arg2: U) { + let a0 = ; + let a1 = ; + let a2 = ; + let a3 = ; + let a4 = ; + let a5 = ; + let a6 = ; +} + +declare function Link(l: {func: (arg: U)=>void}): JSX.Element; +declare function Link(l: {func: (arg1:U, arg2: string)=>void}): JSX.Element; +function createLink(func: (a: number)=>void) { + let o = + let o1 = {}} />; +} \ No newline at end of file diff --git a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments4.tsx b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments4.tsx new file mode 100644 index 00000000000..4be582dab5c --- /dev/null +++ b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentsWithTypeArguments4.tsx @@ -0,0 +1,17 @@ +// @filename: file.tsx +// @jsx: preserve +// @module: amd +// @noLib: true +// @libFiles: react.d.ts,lib.d.ts + +import React = require('react') + +declare function OverloadComponent(): JSX.Element; +declare function OverloadComponent(attr: {b: U, a: string, "ignore-prop": boolean}): JSX.Element; +declare function OverloadComponent(attr: {b: U, a: T}): JSX.Element; + +// Error +function Baz(arg1: T, arg2: U) { + let a0 = + let a2 = // missing a +} \ No newline at end of file