Skip to content

Commit c81c003

Browse files
Andaristemmatown
authored andcommitted
Add TS types to util packages - hash, memoize, weak-memoize (#1503)
1 parent 95b37bb commit c81c003

File tree

17 files changed

+303
-6
lines changed

17 files changed

+303
-6
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"releases": [
3+
{ "name": "@emotion/hash", "type": "patch" },
4+
{ "name": "@emotion/memoize", "type": "patch" },
5+
{ "name": "@emotion/weak-memoize", "type": "patch" }
6+
],
7+
"dependents": [
8+
{
9+
"name": "babel-plugin-emotion",
10+
"type": "patch",
11+
"dependencies": [
12+
"@emotion/serialize",
13+
"@emotion/hash",
14+
"@emotion/memoize"
15+
]
16+
},
17+
{
18+
"name": "@emotion/cache",
19+
"type": "patch",
20+
"dependencies": ["@emotion/hash", "@emotion/weak-memoize"]
21+
},
22+
{
23+
"name": "@emotion/serialize",
24+
"type": "patch",
25+
"dependencies": ["@emotion/hash", "@emotion/memoize"]
26+
},
27+
{
28+
"name": "@emotion/is-prop-valid",
29+
"type": "patch",
30+
"dependencies": ["@emotion/memoize"]
31+
},
32+
{
33+
"name": "emotion-theming",
34+
"type": "patch",
35+
"dependencies": ["@emotion/weak-memoize"]
36+
},
37+
{
38+
"name": "@emotion/primitives",
39+
"type": "patch",
40+
"dependencies": [
41+
"babel-plugin-emotion",
42+
"@emotion/is-prop-valid",
43+
"emotion-theming"
44+
]
45+
},
46+
{
47+
"name": "@emotion/styled-base",
48+
"type": "patch",
49+
"dependencies": ["@emotion/serialize", "@emotion/is-prop-valid"]
50+
}
51+
]
52+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add TS types to util packages - hash, memoize & weak-memoize

packages/hash/package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@
44
"description": "A MurmurHash2 implementation",
55
"main": "dist/hash.cjs.js",
66
"module": "dist/hash.esm.js",
7+
"types": "types/index.d.ts",
78
"license": "MIT",
89
"repository": "https://github.com/emotion-js/emotion/tree/master/packages/hash",
910
"publishConfig": {
1011
"access": "public"
1112
},
1213
"files": [
1314
"src",
14-
"dist"
15+
"dist",
16+
"types"
1517
],
18+
"scripts": {
19+
"test:typescript": "dtslint types"
20+
},
21+
"devDependencies": {
22+
"dtslint": "^0.3.0"
23+
},
1624
"browser": {
1725
"./dist/hash.cjs.js": "./dist/hash.browser.cjs.js",
1826
"./dist/hash.esm.js": "./dist/hash.browser.esm.js"
1927
}
20-
}
28+
}

packages/hash/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function murmurhash2_32_gc(str: string): string

packages/hash/types/tests.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import hash from '@emotion/hash'
2+
3+
// $ExpectType string
4+
hash('color: hotpink;')
5+
6+
// $ExpectError
7+
hash()
8+
// $ExpectError
9+
const hashed2: number = hash('color: hotpink;')
10+
// $ExpectError
11+
hash(42)
12+
// $ExpectError
13+
hash({})
14+
// $ExpectError
15+
hash('color: hotpink;', 'background-color: #fff;')

packages/hash/types/tsconfig.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "../",
4+
"forceConsistentCasingInFileNames": true,
5+
"lib": [
6+
"es6",
7+
"dom"
8+
],
9+
"module": "commonjs",
10+
"noEmit": true,
11+
"noImplicitAny": true,
12+
"noImplicitThis": true,
13+
"strict": true,
14+
"strictNullChecks": true,
15+
"strictFunctionTypes": true,
16+
"target": "es5",
17+
"typeRoots": [
18+
"../"
19+
],
20+
"types": []
21+
},
22+
"include": [
23+
"./*.ts",
24+
"./*.tsx"
25+
]
26+
}

packages/hash/types/tslint.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"extends": "dtslint/dtslint.json",
3+
"rules": {
4+
"array-type": [
5+
true,
6+
"generic"
7+
],
8+
"import-spacing": false,
9+
"semicolon": false,
10+
"whitespace": [
11+
true,
12+
"check-branch",
13+
"check-decl",
14+
"check-operator",
15+
"check-module",
16+
"check-rest-spread",
17+
"check-type",
18+
"check-typecast",
19+
"check-type-operator",
20+
"check-preblock"
21+
],
22+
23+
"no-unnecessary-generics": false
24+
}
25+
}

packages/memoize/package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@
44
"description": "emotion's memoize utility",
55
"main": "dist/memoize.cjs.js",
66
"module": "dist/memoize.esm.js",
7+
"types": "types/index.d.ts",
78
"license": "MIT",
89
"repository": "https://github.com/emotion-js/emotion/tree/master/packages/memoize",
10+
"scripts": {
11+
"test:typescript": "dtslint types"
12+
},
913
"publishConfig": {
1014
"access": "public"
1115
},
16+
"devDependencies": {
17+
"dtslint": "^0.3.0"
18+
},
1219
"files": [
1320
"src",
14-
"dist"
21+
"dist",
22+
"types"
1523
],
1624
"browser": {
1725
"./dist/memoize.cjs.js": "./dist/memoize.browser.cjs.js",
1826
"./dist/memoize.esm.js": "./dist/memoize.browser.esm.js"
1927
}
20-
}
28+
}

packages/memoize/types/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type Fn<T> = (key: string) => T
2+
3+
export default function memoize<T>(fn: Fn<T>): Fn<T>

packages/memoize/types/tests.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import memoize from '@emotion/memoize'
2+
3+
// $ExpectType string[]
4+
memoize((arg: string) => [arg])('foo')
5+
6+
// $ExpectError
7+
memoize((arg: number) => [arg])

0 commit comments

Comments
 (0)