Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
feat(TS): add typescript typings for preact (#416)
Browse files Browse the repository at this point in the history
* Disable TS emit so we do not need to rimraf

* Create separate tsconfig for react

* Add typescript typings for preact

* Patch preact package.json with typings location

* Add myself to contributors
  • Loading branch information
aaronjensen authored and Kent C. Dodds committed May 9, 2018
1 parent 3f03298 commit f556645
Show file tree
Hide file tree
Showing 24 changed files with 3,594 additions and 26 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,15 @@
"contributions": [
"code"
]
},
{
"login": "aaronjensen",
"name": "Aaron Jensen",
"avatar_url": "https://avatars3.githubusercontent.com/u/8588?v=4",
"profile": "https://twitter.com/aaronjensen",
"contributions": [
"code"
]
}
]
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ test-ts
yarn.lock
package-lock.json
.vscode
preact/
/preact/
.eslintcache
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[![downloads][downloads-badge]][npmcharts]
[![MIT License][license-badge]][license]

[![All Contributors](https://img.shields.io/badge/all_contributors-64-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-65-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Chat][chat-badge]][chat]
[![Code of Conduct][coc-badge]][coc]
Expand Down Expand Up @@ -174,7 +174,7 @@ Thanks goes to these people ([emoji key][emojis]):
| [<img src="https://avatars2.githubusercontent.com/u/5257243?v=3" width="100px;"/><br /><sub><b>WillowHQ</b></sub>](https://github.com/WillowHQ)<br />[📖](https://github.com/paypal/glamorous/commits?author=WillowHQ "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/12202757?v=4" width="100px;"/><br /><sub><b>Mohammad Rajabifard</b></sub>](https://tarino.ir)<br />[🐛](https://github.com/paypal/glamorous/issues?q=author%3Amorajabi "Bug reports") [📖](https://github.com/paypal/glamorous/commits?author=morajabi "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/17005317?v=3" width="100px;"/><br /><sub><b>Omar Albacha</b></sub>](https://github.com/Oalbacha)<br />[💻](https://github.com/paypal/glamorous/commits?author=Oalbacha "Code") [📖](https://github.com/paypal/glamorous/commits?author=Oalbacha "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/28659384?v=3" width="100px;"/><br /><sub><b>tdeschryver</b></sub>](https://github.com/tdeschryver)<br />[💻](https://github.com/paypal/glamorous/commits?author=tdeschryver "Code") [⚠️](https://github.com/paypal/glamorous/commits?author=tdeschryver "Tests") | [<img src="https://avatars0.githubusercontent.com/u/4955191?v=4" width="100px;"/><br /><sub><b>Dylan Mozlowski</b></sub>](https://github.com/DylanMoz)<br />[💻](https://github.com/paypal/glamorous/commits?author=DylanMoz "Code") | [<img src="https://avatars2.githubusercontent.com/u/3275424?v=4" width="100px;"/><br /><sub><b>andretshurotshka</b></sub>](https://github.com/goodmind)<br />[💻](https://github.com/paypal/glamorous/commits?author=goodmind "Code") [⚠️](https://github.com/paypal/glamorous/commits?author=goodmind "Tests") | [<img src="https://avatars3.githubusercontent.com/u/12836237?v=4" width="100px;"/><br /><sub><b>Danila</b></sub>](https://github.com/O4epegb)<br />[⚠️](https://github.com/paypal/glamorous/commits?author=O4epegb "Tests") |
| [<img src="https://avatars3.githubusercontent.com/u/12473268?v=4" width="100px;"/><br /><sub><b>Junyoung Clare Jang</b></sub>](http://ailrun.github.io/)<br />[💻](https://github.com/paypal/glamorous/commits?author=Ailrun "Code") [⚠️](https://github.com/paypal/glamorous/commits?author=Ailrun "Tests") | [<img src="https://avatars2.githubusercontent.com/u/897575?v=4" width="100px;"/><br /><sub><b>Björn Ricks</b></sub>](https://twitter.com/bjoernricks)<br />[🐛](https://github.com/paypal/glamorous/issues?q=author%3Abjoernricks "Bug reports") [💻](https://github.com/paypal/glamorous/commits?author=bjoernricks "Code") [📖](https://github.com/paypal/glamorous/commits?author=bjoernricks "Documentation") [⚠️](https://github.com/paypal/glamorous/commits?author=bjoernricks "Tests") | [<img src="https://avatars0.githubusercontent.com/u/4934193?v=4" width="100px;"/><br /><sub><b>Tyler Deitz</b></sub>](http://tylerdeitz.com)<br />[💻](https://github.com/paypal/glamorous/commits?author=tvler "Code") | [<img src="https://avatars2.githubusercontent.com/u/16104985?v=4" width="100px;"/><br /><sub><b>Shovan Chatterjee</b></sub>](https://twitter.com/shovan_ch)<br />[📖](https://github.com/paypal/glamorous/commits?author=shovanch "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/6839660?v=4" width="100px;"/><br /><sub><b>johnjessewood</b></sub>](https://github.com/johnjesse)<br />[💻](https://github.com/paypal/glamorous/commits?author=johnjesse "Code") | [<img src="https://avatars3.githubusercontent.com/u/856386?v=4" width="100px;"/><br /><sub><b>Daniel</b></sub>](https://www.danielberndt.net)<br />[💻](https://github.com/paypal/glamorous/commits?author=danielberndt "Code") [⚠️](https://github.com/paypal/glamorous/commits?author=danielberndt "Tests") | [<img src="https://avatars0.githubusercontent.com/u/174864?v=4" width="100px;"/><br /><sub><b>Ken Powers</b></sub>](https://knpw.rs)<br />[🤔](#ideas-knpwrs "Ideas, Planning, & Feedback") [💡](#example-knpwrs "Examples") |
| [<img src="https://avatars1.githubusercontent.com/u/442932?v=4" width="100px;"/><br /><sub><b>John Grishin</b></sub>](http://johngrish.in)<br />[🐛](https://github.com/paypal/glamorous/issues?q=author%3Aexah "Bug reports") [💻](https://github.com/paypal/glamorous/commits?author=exah "Code") [⚠️](https://github.com/paypal/glamorous/commits?author=exah "Tests") | [<img src="https://avatars3.githubusercontent.com/u/200528?v=4" width="100px;"/><br /><sub><b>Mordy Tikotzky</b></sub>](https://github.com/tikotzky)<br />[🐛](https://github.com/paypal/glamorous/issues?q=author%3Atikotzky "Bug reports") [💻](https://github.com/paypal/glamorous/commits?author=tikotzky "Code") | [<img src="https://avatars3.githubusercontent.com/u/1027024?v=4" width="100px;"/><br /><sub><b>Alasdair McLeay</b></sub>](https://github.com/penx)<br />[💡](#example-penx "Examples") | [<img src="https://avatars1.githubusercontent.com/u/4171528?v=4" width="100px;"/><br /><sub><b>Ardamis Yeshak</b></sub>](https://github.com/zabute)<br />[🔧](#tool-zabute "Tools") | [<img src="https://avatars2.githubusercontent.com/u/3729628?v=4" width="100px;"/><br /><sub><b>Matthew Armstrong</b></sub>](https://github.com/raingerber)<br />[⚠️](https://github.com/paypal/glamorous/commits?author=raingerber "Tests") | [<img src="https://avatars3.githubusercontent.com/u/876694?v=4" width="100px;"/><br /><sub><b>Wu Haotian</b></sub>](https://github.com/whtsky)<br />[💻](https://github.com/paypal/glamorous/commits?author=whtsky "Code") [⚠️](https://github.com/paypal/glamorous/commits?author=whtsky "Tests") | [<img src="https://avatars1.githubusercontent.com/u/7829175?v=4" width="100px;"/><br /><sub><b>Viktor Ivarsson</b></sub>](https://github.com/viktorivarsson)<br />[💻](https://github.com/paypal/glamorous/commits?author=viktorivarsson "Code") |
| [<img src="https://avatars1.githubusercontent.com/u/11481355?v=4" width="100px;"/><br /><sub><b>Mitchell Hamilton</b></sub>](https://hamil.town)<br />[💻](https://github.com/paypal/glamorous/commits?author=mitchellhamilton "Code") |
| [<img src="https://avatars1.githubusercontent.com/u/11481355?v=4" width="100px;"/><br /><sub><b>Mitchell Hamilton</b></sub>](https://hamil.town)<br />[💻](https://github.com/paypal/glamorous/commits?author=mitchellhamilton "Code") | [<img src="https://avatars3.githubusercontent.com/u/8588?v=4" width="100px;"/><br /><sub><b>Aaron Jensen</b></sub>](https://twitter.com/aaronjensen)<br />[💻](https://github.com/paypal/glamorous/commits?author=aaronjensen "Code") |

<!-- ALL-CONTRIBUTORS-LIST:END -->

Expand Down
9 changes: 9 additions & 0 deletions other/patch-preact-package-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fs = require('fs')
const path = require('path')

const packageJsonPath = path.resolve(__dirname, '..', 'preact', 'package.json')

const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
packageJson.typings = '../typings/preact/glamorous.d.ts'

fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"build:main": "kcd-scripts build --bundle --p-react --no-clean",
"build:tiny":
"npm run build:main -- --no-package-json --environment BUILD_TINY",
"postbuild": "node other/patch-preact-package-json.js",
"lint": "kcd-scripts lint",
"test": "kcd-scripts test",
"test:cover": "kcd-scripts test --coverage",
Expand Down Expand Up @@ -60,7 +61,7 @@
"kcd-scripts": "^0.36.0",
"node": "^8.9.4",
"npm-run-all": "^4.1.2",
"preact": "^8.2.7",
"preact": "^8.2.9",
"preval.macro": "^1.0.2",
"prop-types": "^15.5.10",
"react": "^16.2.0",
Expand Down
89 changes: 88 additions & 1 deletion src/__tests__/__snapshots__/typescript.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,93 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Typescript: Typescript expected failures 1`] = `
exports[`Typescript Preact: Typescript expected failures 1`] = `
"test/preact/should-fail.test.tsx(9,61): error TS2345: Argument of type '{ fillRule: \\"cat\\"; }' is not assignable to parameter of type 'StyleArgument<SVGProperties, {}>'.
Type '{ fillRule: \\"cat\\"; }' is not assignable to type '(string | SVGProperties | StyleFunction<SVGProperties, {}>)[]'.
Property 'length' is missing in type '{ fillRule: \\"cat\\"; }'.
test/preact/should-fail.test.tsx(13,66): error TS2345: Argument of type '{ fillRule: \\"cat\\"; }' is not assignable to parameter of type 'StyleArgument<SVGProperties, {}>'.
Type '{ fillRule: \\"cat\\"; }' is not assignable to type '(string | SVGProperties | StyleFunction<SVGProperties, {}>)[]'.
Property 'length' is missing in type '{ fillRule: \\"cat\\"; }'.
test/preact/should-fail.test.tsx(17,68): error TS2345: Argument of type '() => { fillRule: string; }' is not assignable to parameter of type 'StyleArgument<SVGProperties, {}>'.
Type '() => { fillRule: string; }' is not assignable to type '(string | SVGProperties | StyleFunction<SVGProperties, {}>)[]'.
Property 'push' is missing in type '() => { fillRule: string; }'.
test/preact/should-fail.test.tsx(23,61): error TS2345: Argument of type '{ float: \\"cat\\"; }' is not assignable to parameter of type 'StyleArgument<CSSProperties, {}>'.
Type '{ float: \\"cat\\"; }' is not assignable to type '(string | CSSProperties | StyleFunction<CSSProperties, {}>)[]'.
Property 'length' is missing in type '{ float: \\"cat\\"; }'.
test/preact/should-fail.test.tsx(27,66): error TS2345: Argument of type '{ float: \\"cat\\"; }' is not assignable to parameter of type 'StyleArgument<CSSProperties, {}>'.
Type '{ float: \\"cat\\"; }' is not assignable to type '(string | CSSProperties | StyleFunction<CSSProperties, {}>)[]'.
Property 'length' is missing in type '{ float: \\"cat\\"; }'.
test/preact/should-fail.test.tsx(31,64): error TS2345: Argument of type '() => { float: string; }' is not assignable to parameter of type 'StyleArgument<CSSProperties, {}>'.
Type '() => { float: string; }' is not assignable to type '(string | CSSProperties | StyleFunction<CSSProperties, {}>)[]'.
Property 'push' is missing in type '() => { float: string; }'.
test/preact/should-fail.test.tsx(35,69): error TS2345: Argument of type '() => { float: string; }' is not assignable to parameter of type 'StyleArgument<CSSProperties, {}>'.
Type '() => { float: string; }' is not assignable to type '(string | CSSProperties | StyleFunction<CSSProperties, {}>)[]'.
Property 'push' is missing in type '() => { float: string; }'.
test/preact/should-fail.test.tsx(49,55): error TS2345: Argument of type '{ fillRule: \\"cat\\"; }' is not assignable to parameter of type 'StyleArgument<CSSProperties, TestComponentProps & object>'.
Type '{ fillRule: \\"cat\\"; }' is not assignable to type '(string | CSSProperties | StyleFunction<CSSProperties, TestComponentProps & object>)[]'.
Property 'length' is missing in type '{ fillRule: \\"cat\\"; }'.
test/preact/should-fail.test.tsx(53,57): error TS2345: Argument of type '() => { fillRule: string; }' is not assignable to parameter of type 'StyleArgument<CSSProperties, TestComponentProps & object>'.
Type '() => { fillRule: string; }' is not assignable to type '(string | CSSProperties | StyleFunction<CSSProperties, TestComponentProps & object>)[]'.
Property 'push' is missing in type '() => { fillRule: string; }'.
test/preact/should-fail.test.tsx(57,61): error TS2345: Argument of type '{ float: \\"cat\\"; }' is not assignable to parameter of type 'StyleArgument<CSSProperties, TestComponentProps & object>'.
Type '{ float: \\"cat\\"; }' is not assignable to type '(string | CSSProperties | StyleFunction<CSSProperties, TestComponentProps & object>)[]'.
Property 'length' is missing in type '{ float: \\"cat\\"; }'.
test/preact/should-fail.test.tsx(61,64): error TS2345: Argument of type '() => { float: string; }' is not assignable to parameter of type 'StyleArgument<CSSProperties, TestComponentProps & object>'.
Type '() => { float: string; }' is not assignable to type '(string | CSSProperties | StyleFunction<CSSProperties, TestComponentProps & object>)[]'.
Property 'push' is missing in type '() => { float: string; }'.
test/preact/should-fail.test.tsx(79,26): error TS2551: Property 'colors' does not exist on type 'ExampleTheme'. Did you mean 'color'?
test/preact/should-fail.test.tsx(90,47): error TS2344: Type 'PropsWithoutTheme' does not satisfy the constraint '{ theme: any; }'.
Property 'theme' is missing in type 'PropsWithoutTheme'.
test/preact/should-fail.test.tsx(98,11): error TS2345: Argument of type 'FunctionalComponent<object>' is not assignable to parameter of type '\\"tspan\\"'.
test/preact/should-fail.test.tsx(113,18): error TS2551: Property 'visibles' does not exist on type '{ theme: any; } & ExampleComponentProps & object'. Did you mean 'visible'?
test/preact/should-fail.test.tsx(125,29): error TS2322: Type '{ visible: string; }' is not assignable to type 'Readonly<ExampleComponentProps & object & ExtraGlamorousProps & Attributes & { children?: Compone...'.
Types of property 'visible' are incompatible.
Type 'string' is not assignable to type 'boolean'.
test/preact/should-fail.test.tsx(126,5): error TS2322: Type '{}' is not assignable to type 'Readonly<ExampleComponentProps & object & ExtraGlamorousProps & Attributes & { children?: Compone...'.
Property 'visible' is missing in type '{}'.
test/preact/should-fail.test.tsx(127,32): error TS2322: Type '{ visible: string; }' is not assignable to type 'Readonly<HTMLAttributes & { visible: boolean; } & object & ExtraGlamorousProps & Attributes & { c...'.
Types of property 'visible' are incompatible.
Type 'string' is not assignable to type 'boolean'.
test/preact/should-fail.test.tsx(128,5): error TS2322: Type '{}' is not assignable to type 'Readonly<HTMLAttributes & { visible: boolean; } & object & ExtraGlamorousProps & Attributes & { c...'.
Property 'visible' is missing in type '{}'.
test/preact/should-fail.test.tsx(132,21): error TS2345: Argument of type '{ allowReorder: boolean; }' is not assignable to parameter of type 'StyleArgument<SVGProperties, object & {}>'.
Type '{ allowReorder: boolean; }' is not assignable to type '(string | SVGProperties | StyleFunction<SVGProperties, object & {}>)[]'.
Property 'length' is missing in type '{ allowReorder: boolean; }'.
test/preact/should-fail.test.tsx(133,18): error TS2345: Argument of type '{ color: boolean; }' is not assignable to parameter of type 'StyleArgument<CSSProperties, object & {}>'.
Type '{ color: boolean; }' is not assignable to type '(string | CSSProperties | StyleFunction<CSSProperties, object & {}>)[]'.
Property 'length' is missing in type '{ color: boolean; }'.
test/preact/should-fail.test.tsx(137,4): error TS2345: Argument of type 'FunctionalComponent<ExampleComponentProps>' is not assignable to parameter of type '\\"tspan\\"'.
test/preact/should-fail.test.tsx(137,22): error TS7006: Parameter 'props' implicitly has an 'any' type.
test/preact/should-fail.test.tsx(142,12): error TS2365: Operator '===' cannot be applied to types 'boolean' and '\\"\\"'.
test/preact/should-fail.test.tsx(157,15): error TS2551: Property 'colors' does not exist on type 'ShouldClassNameUpdateProps'. Did you mean 'color'?
test/preact/should-fail.test.tsx(164,35): error TS2345: Argument of type 'FunctionalComponent<ShouldClassNameUpdateProps>' is not assignable to parameter of type '\\"tspan\\"'.
test/preact/should-fail.test.tsx(182,17): error TS2551: Property 'colors' does not exist on type 'ShouldClassNameUpdateContext'. Did you mean 'color'?
test/preact/should-fail.test.tsx(191,11): error TS2345: Argument of type '\\"div\\"' is not assignable to parameter of type '\\"tspan\\"'.
test/preact/should-fail.test.tsx(197,4): error TS2345: Argument of type '(props: { visible: boolean; }) => { primaryColor: boolean; }' is not assignable to parameter of type 'StyleArgument<CSSProperties, { visible: boolean; }>'.
Type '(props: { visible: boolean; }) => { primaryColor: boolean; }' is not assignable to type '(string | CSSProperties | StyleFunction<CSSProperties, { visible: boolean; }>)[]'.
Property 'push' is missing in type '(props: { visible: boolean; }) => { primaryColor: boolean; }'.
test/preact/should-fail.test.tsx(201,1): error TS2554: Expected 1 arguments, but got 0.
test/preact/should-fail.test.tsx(202,30): error TS2345: Argument of type '\\"\\"' is not assignable to parameter of type 'object'.
test/preact/should-fail.test.tsx(203,30): error TS2345: Argument of type 'false' is not assignable to parameter of type 'object'.
test/preact/should-fail.test.tsx(225,19): error TS2559: Type '{ d: string; }' has no properties in common with type 'Readonly<HTMLAttributes & Partial<{ primaryColor: string; }> & Pick<{ theme?: any; }, never> & { ...'.
test/preact/should-fail.test.tsx(226,19): error TS2322: Type '{ primaryColor: number; }' is not assignable to type 'Readonly<HTMLAttributes & Partial<{ primaryColor: string; }> & Pick<{ theme?: any; }, never> & { ...'.
Types of property 'primaryColor' are incompatible.
Type 'number' is not assignable to type 'string | undefined'.
test/preact/should-fail.test.tsx(227,31): error TS2559: Type '{ d: string; }' has no properties in common with type 'Readonly<Partial<{ primaryColor: string; }> & Pick<{ theme: any; }, never> & ExtraGlamorousProps ...'.
test/preact/should-fail.test.tsx(228,31): error TS2322: Type '{ primaryColor: number; }' is not assignable to type 'Readonly<Partial<{ primaryColor: string; }> & Pick<{ theme: any; }, never> & ExtraGlamorousProps ...'.
Types of property 'primaryColor' are incompatible.
Type 'number' is not assignable to type 'string | undefined'.
test/preact/should-fail.test.tsx(229,31): error TS2559: Type '{ d: string; }' has no properties in common with type 'Readonly<object & Partial<{ primaryColor: string; }> & ExtraGlamorousProps & Attributes & { child...'.
test/preact/should-fail.test.tsx(230,31): error TS2322: Type '{ primaryColor: number; }' is not assignable to type 'Readonly<object & Partial<{ primaryColor: string; }> & ExtraGlamorousProps & Attributes & { child...'.
Types of property 'primaryColor' are incompatible.
Type 'number' is not assignable to type 'string | undefined'.
test/preact/should-fail.test.tsx(266,38): error TS2559: Type '{ display: string; }' has no properties in common with type 'Readonly<object & ExtraGlamorousProps & Attributes & { children?: ComponentChild[] | undefined; r...'.
test/preact/should-fail.test.tsx(267,42): error TS2559: Type '{ display: string; }' has no properties in common with type 'Readonly<object & ExtraGlamorousProps & Attributes & { children?: ComponentChild[] | undefined; r...'.
test/preact/should-fail.test.tsx(270,32): error TS2559: Type '{ display: string; }' has no properties in common with type 'Readonly<HTMLAttributes & object & ExtraGlamorousProps & Attributes & { children?: ComponentChild...'.
test/preact/should-fail.test.tsx(271,36): error TS2559: Type '{ display: string; }' has no properties in common with type 'Readonly<HTMLAttributes & object & ExtraGlamorousProps & Attributes & { children?: ComponentChild...'.
"
`;
exports[`Typescript React: Typescript expected failures 1`] = `
"test/should-fail.test.tsx(10,3): error TS2345: Argument of type '{ fillRule: \\"cat\\"; }' is not assignable to parameter of type 'StyleArgument<SVGProperties, {}>'.
Type '{ fillRule: \\"cat\\"; }' is not assignable to type '(string | SVGProperties | StyleFunction<SVGProperties, {}>)[]'.
Property 'length' is missing in type '{ fillRule: \\"cat\\"; }'.
Expand Down
Loading

0 comments on commit f556645

Please sign in to comment.