Add tests for generic stateless function component

This commit is contained in:
Kanchalai Tanglertsampan
2017-01-18 15:16:59 -08:00
parent 9e3da083da
commit 19d05484d8
4 changed files with 118 additions and 0 deletions
@@ -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<K,V>(l: {key1: K, value: V}): JSX.Element;
// OK
function Baz<T,U>(key1: T, value: U) {
let a0 = <ComponentWithTwoAttributes key1={key1} value={value} />
let a1 = <ComponentWithTwoAttributes {...{key1, value: value}} key="Component" />
}
// OK
declare function Component<U>(l: U): JSX.Element;
function createComponent<T extends {prop: number}>(arg:T) {
let a1 = <Component {...arg} />;
let a2 = <Component {...arg} prop1 />;
}
declare function ComponentSpecific<U>(l: {prop: U}): JSX.Element;
declare function ComponentSpecific1<U>(l: {prop: U, "ignore-prop": number}): JSX.Element;
// OK
function Bar<T extends {prop: number}>(arg: T) {
let a1 = <ComponentSpecific {...arg} ignore-prop="hi" />; // U is number
let a2 = <ComponentSpecific1 {...arg} ignore-prop={10} />; // U is number
let a3 = <ComponentSpecific {...arg} prop="hello" />; // U is "hello"
}
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
// OK
function createLink(func: (a: number)=>void) {
let o = <Link func={func} />
}
function createLink1(func: (a: number)=>boolean) {
let o = <Link func={func} />
}
@@ -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<U>(l: {prop: U, "ignore-prop": string}): JSX.Element;
declare function ComponentSpecific2<U>(l: {prop: U}): JSX.Element;
// Error
function Bar<T extends {prop: number}>(arg: T) {
let a1 = <ComponentSpecific1 {...arg} ignore-prop={10} />;
}
// Error
function Baz<T>(arg: T) {
let a0 = <ComponentSpecific1 {...arg} />
}
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
// Error
function createLink(func: (a: number, b: string)=>void) {
let o = <Link func={func} />
}
@@ -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<U>(): JSX.Element;
declare function OverloadComponent<U>(attr: {b: U, a?: string, "ignore-prop": boolean}): JSX.Element;
declare function OverloadComponent<T, U>(attr: {b: U, a: T}): JSX.Element;
// OK
function Baz<T extends {b: number}, U extends {a: boolean, b:string}>(arg1: T, arg2: U) {
let a0 = <OverloadComponent {...arg1} a="hello" ignore-prop />;
let a1 = <OverloadComponent {...arg2} ignore-pro="hello world" />;
let a2 = <OverloadComponent {...arg2} />;
let a3 = <OverloadComponent {...arg1} ignore-prop />;
let a4 = <OverloadComponent />;
let a5 = <OverloadComponent {...arg2} ignore-prop="hello" {...arg1} />;
let a6 = <OverloadComponent {...arg2} ignore-prop {...arg1} />;
}
declare function Link<U>(l: {func: (arg: U)=>void}): JSX.Element;
declare function Link<U>(l: {func: (arg1:U, arg2: string)=>void}): JSX.Element;
function createLink(func: (a: number)=>void) {
let o = <Link func={func} />
let o1 = <Link func={(a:number, b:string)=>{}} />;
}
@@ -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<U>(): JSX.Element;
declare function OverloadComponent<U>(attr: {b: U, a: string, "ignore-prop": boolean}): JSX.Element;
declare function OverloadComponent<T, U>(attr: {b: U, a: T}): JSX.Element;
// Error
function Baz<T extends {b: number}, U extends {a: boolean, b:string}>(arg1: T, arg2: U) {
let a0 = <OverloadComponent a={arg1.b}/>
let a2 = <OverloadComponent {...arg1} ignore-prop /> // missing a
}