-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for types (only works in 3.9.0)
- Loading branch information
Showing
1 changed file
with
239 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
/** @jsx createElement */ | ||
import { createElement, Component, FunctionComponent, Context, GeneratorComponent, Child } from ".."; | ||
|
||
describe("types", () => { | ||
|
||
type MyProps = { | ||
message: string; | ||
}; | ||
let elem: any; | ||
|
||
test("Primitive Components", () => { | ||
|
||
const MyString: Component = 'Hello'; | ||
const MyNumber: Component = 10; | ||
const MyBoolean: Component = true; | ||
const MyNull: Component = null; | ||
const MyUndefined: Component = undefined; | ||
const MyElement: Component = <a></a>; | ||
|
||
// @ts-expect-error | ||
const NotComponent: Component = {}; | ||
|
||
// @ts-expect-error | ||
const StringsDontHaveProps: Component<MyProps> = 'Hello'; | ||
|
||
}); | ||
|
||
test ("Components", () => { | ||
const MyFunctionComponent: Component<MyProps> = function(this, props) { | ||
const ctx: Context<MyProps> = this; | ||
let message: string = props.message; | ||
// @ts-expect-error | ||
let unexpected = props.unexpected; | ||
|
||
return <div></div>; | ||
} | ||
// @ts-expect-error | ||
elem = <MyFunctionComponent />; | ||
elem = <MyFunctionComponent message={'message'} />; | ||
|
||
const MyAsyncFunctionComponent: Component<MyProps> = async function (this, props) { | ||
const ctx: Context<MyProps> = this; | ||
let message: string = props.message; | ||
// @ts-expect-error | ||
let unexpected = props.unexpected; | ||
|
||
return <div></div>; | ||
} | ||
// @ts-expect-error | ||
elem = <MyAsyncFunctionComponent />; | ||
elem = <MyAsyncFunctionComponent message={'message'} />; | ||
|
||
const MyGeneratorComponent: Component<MyProps> = function* (this, initialProps) { | ||
const ctx: Context<MyProps> = this; | ||
let message: string = initialProps.message; | ||
// @ts-expect-error | ||
let unexpected = initialProps.unexpected; | ||
|
||
for (const newProps of this) { | ||
let newMessage: string = initialProps.message; | ||
// @ts-expect-error | ||
let newUnexpected = newProps.unexpected; | ||
yield <div></div>; | ||
} | ||
|
||
return <div></div>; | ||
} | ||
// @ts-expect-error | ||
elem = <MyGeneratorComponent />; | ||
elem = <MyGeneratorComponent message={'message'} />; | ||
|
||
const MyAsyncGeneratorComponent: Component<MyProps> = async function* (this, initialProps) { | ||
const ctx: Context<MyProps> = this; | ||
let message: string = initialProps.message; | ||
// @ts-expect-error | ||
let unexpected = initialProps.unexpected; | ||
|
||
for await (const newProps of this) { | ||
let newMessage: string = initialProps.message; | ||
// @ts-expect-error | ||
let newUnexpected = newProps.unexpected; | ||
yield <div></div>; | ||
} | ||
|
||
return <div></div>; | ||
} | ||
// @ts-expect-error | ||
elem = <MyAsyncGeneratorComponent />; | ||
elem = <MyAsyncGeneratorComponent message={'message'} />; | ||
|
||
}); | ||
|
||
test("Function Components", () => { | ||
const MyFunctionComponent: FunctionComponent<MyProps> = function(this, props) { | ||
const ctx: Context<MyProps> = this; | ||
let message: string = props.message; | ||
// @ts-expect-error | ||
let unexpected = props.unexpected; | ||
|
||
return <div></div>; | ||
} | ||
// @ts-expect-error | ||
elem = <MyFunctionComponent />; | ||
elem = <MyFunctionComponent message={'message'} />; | ||
|
||
const MyAsyncFunctionComponent: FunctionComponent<MyProps> = async function (this, props) { | ||
const ctx: Context<MyProps> = this; | ||
let message: string = props.message; | ||
// @ts-expect-error | ||
let unexpected = props.unexpected; | ||
|
||
return <div></div>; | ||
} | ||
// @ts-expect-error | ||
elem = <MyAsyncFunctionComponent />; | ||
elem = <MyAsyncFunctionComponent message={'message'} />; | ||
|
||
// @ts-expect-error | ||
const MyGeneratorComponent: FunctionComponent<MyProps> = function* (this, props) { | ||
yield <div></div>; | ||
} | ||
// @ts-expect-error | ||
const MyAsyncGeneratorComponent: FunctionComponent<MyProps> = async function* (this, props) { | ||
yield <div></div>; | ||
} | ||
}) | ||
|
||
test ("Generator Components", () => { | ||
const MyGeneratorComponent: GeneratorComponent<MyProps> = function* (this, initialProps) { | ||
const ctx: Context<MyProps> = this; | ||
let message: string = initialProps.message; | ||
// @ts-expect-error | ||
let unexpected = initialProps.unexpected; | ||
|
||
for (const newProps of this) { | ||
let newMessage: string = initialProps.message; | ||
// @ts-expect-error | ||
let newUnexpected = newProps.unexpected; | ||
yield <div></div>; | ||
} | ||
|
||
return <div></div>; | ||
} | ||
// @ts-expect-error | ||
elem = <MyGeneratorComponent />; | ||
elem = <MyGeneratorComponent message={'message'} />; | ||
|
||
const MyAsyncGeneratorComponent: GeneratorComponent<MyProps> = async function* (this, initialProps) { | ||
const ctx: Context<MyProps> = this; | ||
let message: string = initialProps.message; | ||
// @ts-expect-error | ||
let unexpected = initialProps.unexpected; | ||
|
||
for await (const newProps of this) { | ||
let newMessage: string = initialProps.message; | ||
// @ts-expect-error | ||
let newUnexpected = newProps.unexpected; | ||
yield <div></div>; | ||
} | ||
|
||
return <div></div>; | ||
} | ||
// @ts-expect-error | ||
elem = <MyAsyncGeneratorComponent />; | ||
elem = <MyAsyncGeneratorComponent message={'message'} />; | ||
|
||
// TODO: add ts-expect-error at some point in the future, I guess? | ||
// This will not pass because the function is infered as any, and any matches Iterator<any, any, any>. | ||
// Hopefully a later typescript version fixes this :( | ||
const MyFunctionComponent: GeneratorComponent<MyProps> = function(this, props) { | ||
return <div></div>; | ||
} | ||
// @ts-expect-error | ||
const MyAsyncFunctionComponent: GeneratorComponent<MyProps> = async function(this, props) { | ||
return <div></div>; | ||
} | ||
}); | ||
|
||
test ("Loose Typings", () => { | ||
function MyFunctionComponent(props: MyProps) { | ||
let message: string = props.message; | ||
// @ts-expect-error | ||
let unexpected = props.unexpected; | ||
|
||
return <div></div>; | ||
} | ||
// @ts-expect-error | ||
elem = <MyFunctionComponent />; | ||
elem = <MyFunctionComponent message={'message'} />; | ||
|
||
async function MyAsyncFunctionComponent(props: MyProps) { | ||
let message: string = props.message; | ||
// @ts-expect-error | ||
let unexpected = props.unexpected; | ||
|
||
return <div></div>; | ||
} | ||
// @ts-expect-error | ||
elem = <MyAsyncFunctionComponent />; | ||
elem = <MyAsyncFunctionComponent message={'message'} />; | ||
|
||
function* MyGeneratorComponent(this: Context, props: MyProps) { | ||
let message: string = props.message; | ||
// @ts-expect-error | ||
let unexpected = props.unexpected; | ||
|
||
for (props of this) { | ||
let newMessage: string = props.message; | ||
// @ts-expect-error | ||
let newUnexpected = props.unexpected; | ||
yield <div></div>; | ||
} | ||
|
||
return <div></div>; | ||
} | ||
// @ts-expect-error | ||
elem = <MyGeneratorComponent />; | ||
elem = <MyGeneratorComponent message={'message'} />; | ||
|
||
async function* MyAsyncGeneratorComponent(this: Context, props: MyProps) { | ||
let message: string = props.message; | ||
// @ts-expect-error | ||
let unexpected = props.unexpected; | ||
|
||
for await (props of this) { | ||
let newMessage: string = props.message; | ||
// @ts-expect-error | ||
let newUnexpected = props.unexpected; | ||
yield <div></div>; | ||
} | ||
|
||
return <div></div>; | ||
} | ||
// @ts-expect-error | ||
elem = <MyAsyncGeneratorComponent />; | ||
elem = <MyAsyncGeneratorComponent message={'message'} />; | ||
}); | ||
|
||
}); |