-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TS types to util packages - hash, memoize, weak-memoize (#1503)
- Loading branch information
Showing
17 changed files
with
303 additions
and
6 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,52 @@ | ||
{ | ||
"releases": [ | ||
{ "name": "@emotion/hash", "type": "patch" }, | ||
{ "name": "@emotion/memoize", "type": "patch" }, | ||
{ "name": "@emotion/weak-memoize", "type": "patch" } | ||
], | ||
"dependents": [ | ||
{ | ||
"name": "babel-plugin-emotion", | ||
"type": "patch", | ||
"dependencies": [ | ||
"@emotion/serialize", | ||
"@emotion/hash", | ||
"@emotion/memoize" | ||
] | ||
}, | ||
{ | ||
"name": "@emotion/cache", | ||
"type": "patch", | ||
"dependencies": ["@emotion/hash", "@emotion/weak-memoize"] | ||
}, | ||
{ | ||
"name": "@emotion/serialize", | ||
"type": "patch", | ||
"dependencies": ["@emotion/hash", "@emotion/memoize"] | ||
}, | ||
{ | ||
"name": "@emotion/is-prop-valid", | ||
"type": "patch", | ||
"dependencies": ["@emotion/memoize"] | ||
}, | ||
{ | ||
"name": "emotion-theming", | ||
"type": "patch", | ||
"dependencies": ["@emotion/weak-memoize"] | ||
}, | ||
{ | ||
"name": "@emotion/primitives", | ||
"type": "patch", | ||
"dependencies": [ | ||
"babel-plugin-emotion", | ||
"@emotion/is-prop-valid", | ||
"emotion-theming" | ||
] | ||
}, | ||
{ | ||
"name": "@emotion/styled-base", | ||
"type": "patch", | ||
"dependencies": ["@emotion/serialize", "@emotion/is-prop-valid"] | ||
} | ||
] | ||
} |
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 @@ | ||
Add TS types to util packages - hash, memoize & weak-memoize |
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
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 @@ | ||
export default function murmurhash2_32_gc(str: string): string |
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,15 @@ | ||
import hash from '@emotion/hash' | ||
|
||
// $ExpectType string | ||
hash('color: hotpink;') | ||
|
||
// $ExpectError | ||
hash() | ||
// $ExpectError | ||
const hashed2: number = hash('color: hotpink;') | ||
// $ExpectError | ||
hash(42) | ||
// $ExpectError | ||
hash({}) | ||
// $ExpectError | ||
hash('color: hotpink;', 'background-color: #fff;') |
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,26 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "../", | ||
"forceConsistentCasingInFileNames": true, | ||
"lib": [ | ||
"es6", | ||
"dom" | ||
], | ||
"module": "commonjs", | ||
"noEmit": true, | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"target": "es5", | ||
"typeRoots": [ | ||
"../" | ||
], | ||
"types": [] | ||
}, | ||
"include": [ | ||
"./*.ts", | ||
"./*.tsx" | ||
] | ||
} |
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,25 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"array-type": [ | ||
true, | ||
"generic" | ||
], | ||
"import-spacing": false, | ||
"semicolon": false, | ||
"whitespace": [ | ||
true, | ||
"check-branch", | ||
"check-decl", | ||
"check-operator", | ||
"check-module", | ||
"check-rest-spread", | ||
"check-type", | ||
"check-typecast", | ||
"check-type-operator", | ||
"check-preblock" | ||
], | ||
|
||
"no-unnecessary-generics": false | ||
} | ||
} |
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
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,3 @@ | ||
type Fn<T> = (key: string) => T | ||
|
||
export default function memoize<T>(fn: Fn<T>): Fn<T> |
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,7 @@ | ||
import memoize from '@emotion/memoize' | ||
|
||
// $ExpectType string[] | ||
memoize((arg: string) => [arg])('foo') | ||
|
||
// $ExpectError | ||
memoize((arg: number) => [arg]) |
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,26 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "../", | ||
"forceConsistentCasingInFileNames": true, | ||
"lib": [ | ||
"es6", | ||
"dom" | ||
], | ||
"module": "commonjs", | ||
"noEmit": true, | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"target": "es5", | ||
"typeRoots": [ | ||
"../" | ||
], | ||
"types": [] | ||
}, | ||
"include": [ | ||
"./*.ts", | ||
"./*.tsx" | ||
] | ||
} |
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,25 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"array-type": [ | ||
true, | ||
"generic" | ||
], | ||
"import-spacing": false, | ||
"semicolon": false, | ||
"whitespace": [ | ||
true, | ||
"check-branch", | ||
"check-decl", | ||
"check-operator", | ||
"check-module", | ||
"check-rest-spread", | ||
"check-type", | ||
"check-typecast", | ||
"check-type-operator", | ||
"check-preblock" | ||
], | ||
|
||
"no-unnecessary-generics": false | ||
} | ||
} |
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
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,5 @@ | ||
type UnaryFn<Arg, Return> = (arg: Arg) => Return | ||
|
||
export default function weakMemoize<Arg extends object, Return>( | ||
func: UnaryFn<Arg, Return> | ||
): UnaryFn<Arg, Return> |
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,36 @@ | ||
import weakMemoize from '@emotion/weak-memoize' | ||
|
||
type Foo = { bar: 'xyz' } | ||
|
||
declare class Qwe { | ||
answer: number | ||
} | ||
|
||
// $ExpectType Array<Foo> | ||
weakMemoize((arg: Foo) => [arg])({ bar: 'xyz' }) | ||
|
||
// $ExpectType string[] | ||
weakMemoize((arg: string) => [arg])('foo') | ||
|
||
// $ExpectError | ||
weakMemoize((arg: Foo) => [arg])(42) | ||
|
||
// $ExpectError | ||
weakMemoize((arg: string) => [arg]) | ||
// $ExpectError | ||
weakMemoize((arg: number) => [arg]) | ||
// $ExpectError | ||
weakMemoize((arg: boolean) => [arg]) | ||
// $ExpectError | ||
weakMemoize((arg: symbol) => [arg]) | ||
// $ExpectError | ||
weakMemoize((arg: void) => [arg]) | ||
// $ExpectError | ||
weakMemoize((arg: null) => [arg]) | ||
// $ExpectError | ||
weakMemoize((arg: undefined) => [arg]) | ||
|
||
weakMemoize((arg: () => void) => [arg]) | ||
weakMemoize((arg: Map<any, any>) => [arg]) | ||
weakMemoize((arg: Set<any>) => [arg]) | ||
weakMemoize((arg: Qwe) => [arg]) |
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,26 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "../", | ||
"forceConsistentCasingInFileNames": true, | ||
"lib": [ | ||
"es6", | ||
"dom" | ||
], | ||
"module": "commonjs", | ||
"noEmit": true, | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"target": "es5", | ||
"typeRoots": [ | ||
"../" | ||
], | ||
"types": [] | ||
}, | ||
"include": [ | ||
"./*.ts", | ||
"./*.tsx" | ||
] | ||
} |
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,25 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"array-type": [ | ||
true, | ||
"generic" | ||
], | ||
"import-spacing": false, | ||
"semicolon": false, | ||
"whitespace": [ | ||
true, | ||
"check-branch", | ||
"check-decl", | ||
"check-operator", | ||
"check-module", | ||
"check-rest-spread", | ||
"check-type", | ||
"check-typecast", | ||
"check-type-operator", | ||
"check-preblock" | ||
], | ||
|
||
"no-unnecessary-generics": false | ||
} | ||
} |