From 9e3da083da517a70b93634623354b8b3aa69cee5 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 8 Nov 2016 09:33:25 -0800 Subject: [PATCH] Add tests for overload stateless function component --- ...tsxStatelessFunctionComponentOverload1.tsx | 44 +++++++++++++ ...tsxStatelessFunctionComponentOverload2.tsx | 37 +++++++++++ ...tsxStatelessFunctionComponentOverload3.tsx | 29 +++++++++ ...tsxStatelessFunctionComponentOverload4.tsx | 39 ++++++++++++ ...tsxStatelessFunctionComponentOverload5.tsx | 62 +++++++++++++++++++ ...tsxStatelessFunctionComponentOverload6.tsx | 62 +++++++++++++++++++ 6 files changed, 273 insertions(+) create mode 100644 tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload1.tsx create mode 100644 tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload2.tsx create mode 100644 tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload3.tsx create mode 100644 tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload4.tsx create mode 100644 tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload5.tsx create mode 100644 tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload6.tsx diff --git a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload1.tsx b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload1.tsx new file mode 100644 index 00000000000..ea950d8b6d4 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload1.tsx @@ -0,0 +1,44 @@ +// @filename: file.tsx +// @jsx: preserve +// @module: amd +// @noLib: true +// @libFiles: react.d.ts,lib.d.ts + +import React = require('react') + +declare function OneThing(k: {yxx: string}): JSX.Element; +declare function OneThing(l: {yy: number, yy1: string}): JSX.Element; +declare function OneThing(l: {yy: number, yy1: string, yy2: boolean}): JSX.Element; +declare function OneThing(l1: {data: string, "data-prop": boolean}): JSX.Element; + +// OK +const c1 = +const c2 = +const c3 = +const c4 = + +declare function TestingOneThing({y1: string}): JSX.Element; +declare function TestingOneThing(j: {"extra-data": string, yy?: string}): JSX.Element; +declare function TestingOneThing(n: {yy: number, direction?: number}): JSX.Element; +declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element; + +// OK +const d1 = ; +const d2 = ; +const d3 = ; +const d4 = ; +const d5 = ; + + +declare function TestingOptional(a: {y1?: string, y2?: number}): JSX.Element; +declare function TestingOptional(a: {y1: boolean, y2?: number, y3: boolean}): JSX.Element; + +// OK +const e1 = +const e2 = +const e3 = +const e4 = +const e5 = +const e6 = + + diff --git a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload2.tsx b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload2.tsx new file mode 100644 index 00000000000..fe2a3eb7477 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload2.tsx @@ -0,0 +1,37 @@ +// @filename: file.tsx +// @jsx: preserve +// @module: amd +// @noLib: true +// @libFiles: react.d.ts,lib.d.ts + +import React = require('react') +declare function OneThing(): JSX.Element; +declare function OneThing(l: {yy: number, yy1: string}): JSX.Element; + +let obj = { + yy: 10, + yy1: "hello" +} + +let obj1 = { + yy: true +} + +let obj2 = { + yy: 500, + "ignore-prop": "hello" +} + +let defaultObj = undefined; + +// OK +const c1 = +const c2 = +const c3 = +const c4 = +const c5 = +const c6 = +const c7 = ; // No error. should pick second overload +const c8 = +const c9 = ; +const c10 = ; diff --git a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload3.tsx b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload3.tsx new file mode 100644 index 00000000000..5a21bcfe736 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload3.tsx @@ -0,0 +1,29 @@ +// @filename: file.tsx +// @jsx: preserve +// @module: amd +// @noLib: true +// @libFiles: react.d.ts,lib.d.ts + +interface Context { + color: any; +} +declare function ZeroThingOrTwoThing(): JSX.Element; +declare function ZeroThingOrTwoThing(l: {yy: number, yy1: string}, context: Context): JSX.Element; + +let obj2 = undefined; + +// OK +const two1 = ; +const two2 = ; +const two3 = ; // it is just any so we allow it to pass through +const two4 = ; // it is just any so we allow it to pass through +const two5 = ; // it is just any so we allow it to pass through + +declare function ThreeThing(l: {y1: string}): JSX.Element; +declare function ThreeThing(l: {y2: string}): JSX.Element; +declare function ThreeThing(l: {yy: number, yy1: string}, context: Context, updater: any): JSX.Element; + +// OK +const three1 = ; +const three2 = ; +const three3 = ; // it is just any so we allow it to pass through \ No newline at end of file diff --git a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload4.tsx b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload4.tsx new file mode 100644 index 00000000000..d94c7a5531c --- /dev/null +++ b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload4.tsx @@ -0,0 +1,39 @@ +// @filename: file.tsx +// @jsx: preserve +// @module: amd +// @noLib: true +// @libFiles: react.d.ts,lib.d.ts + +import React = require('react') +declare function OneThing(): JSX.Element; +declare function OneThing(l: {yy: number, yy1: string}): JSX.Element; + +let obj = { + yy: 10, + yy1: "hello" +} +let obj2 = undefined; + +// Error +const c0 = ; // extra property; +const c1 = ; // missing property; +const c2 = ; // type incompatible; +const c3 = ; // Extra attribute; +const c4 = ; // extra property; +const c5 = ; // type incompatible; +const c6 = ; // Should error as there is extra attribute that doesn't match any. Current it is not +const c7 = ; // Should error as there is extra attribute that doesn't match any. Current it is not + +declare function TestingOneThing(j: {"extra-data": string}): JSX.Element; +declare function TestingOneThing(n: {yy: string, direction?: number}): JSX.Element; + +// Error +const d1 = +const d2 = + +declare function TestingOptional(a: {y1?: string, y2?: number}): JSX.Element; +declare function TestingOptional(a: {y1: boolean, y2?: number, y3: boolean}): JSX.Element; + +// Error +const e1 = +const e2 = diff --git a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload5.tsx b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload5.tsx new file mode 100644 index 00000000000..8821d0adcce --- /dev/null +++ b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload5.tsx @@ -0,0 +1,62 @@ +// @filename: file.tsx +// @jsx: preserve +// @module: amd +// @noLib: true +// @libFiles: react.d.ts,lib.d.ts + +import React = require('react') + +export interface ClickableProps { + children?: string; + className?: string; +} + +export interface ButtonProps extends ClickableProps { + onClick: React.MouseEventHandler; +} + +export interface LinkProps extends ClickableProps { + to: string; +} + +export interface HyphenProps extends ClickableProps { + "data-format": string; +} + +let obj0 = { + to: "world" +}; + +let obj1 = { + children: "hi", + to: "boo" +} + +let obj2 = { + onClick: ()=>{} +} + +let obj3 = undefined; + +export function MainButton(buttonProps: ButtonProps): JSX.Element; +export function MainButton(linkProps: LinkProps): JSX.Element; +export function MainButton(hyphenProps: HyphenProps): JSX.Element; +export function MainButton(props: ButtonProps | LinkProps | HyphenProps): JSX.Element { + const linkProps = props as LinkProps; + if(linkProps.to) { + return this._buildMainLink(props); + } + + return this._buildMainButton(props); +} + +// Error +const b0 = {}}>GO; // extra property; +const b1 = {}} {...obj0}>Hello world; // extra property; +const b2 = ; // extra property +const b3 = {}}} />; // extra property +const b4 = ; // Shoudld erro because Incorrect type; but attributes are any so everything is allowed +const b5 = ; // Spread doesn't retain method declaration +const b6 = ; // incorrect type for optional attribute +const b7 = ; // incorrect type for optional attribute +const b8 = ; // incorrect type for specified hyphanted name \ No newline at end of file diff --git a/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload6.tsx b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload6.tsx new file mode 100644 index 00000000000..2bd372eaa0d --- /dev/null +++ b/tests/cases/conformance/jsx/tsxStatelessFunctionComponentOverload6.tsx @@ -0,0 +1,62 @@ +// @filename: file.tsx +// @jsx: preserve +// @module: amd +// @noLib: true +// @libFiles: react.d.ts,lib.d.ts + +import React = require('react') + +export interface ClickableProps { + children?: string; + className?: string; +} + +export interface ButtonProps extends ClickableProps { + onClick: React.MouseEventHandler; +} + +export interface LinkProps extends ClickableProps { + to: string; +} + +export interface HyphenProps extends ClickableProps { + "data-format": string; +} + +let obj = { + children: "hi", + to: "boo" +} +let obj1 = undefined; +let obj2 = { + onClick: () => {} +} + +export function MainButton(buttonProps: ButtonProps): JSX.Element; +export function MainButton(linkProps: LinkProps): JSX.Element; +export function MainButton(hyphenProps: HyphenProps): JSX.Element; +export function MainButton(props: ButtonProps | LinkProps | HyphenProps): JSX.Element { + const linkProps = props as LinkProps; + if(linkProps.to) { + return this._buildMainLink(props); + } + + return this._buildMainButton(props); +} + +// OK +const b0 = GO; +const b1 = {}}>Hello world; +const b2 = ; +const b3 = ; +const b4 = ; // any; just pick the first overload +const b5 = ; // should pick the second overload +const b6 = ; +const b7 = { console.log("hi") }}} />; +const b8 = ; // OK; method declaration get discarded +const b9 = GO; +const b10 = GO; +const b11 = {}} className="hello" data-format>Hello world; +const b12 = + +