Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[memoize] Migrate to TypeScript #2427

Merged
merged 6 commits into from
Aug 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hip-moons-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@emotion/memoize': minor
---

Source code has been migrated to TypeScript. From now on type declarations will be emitted based on that, instead of being hand-written.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
transform: {
'\\.css$': '<rootDir>/test/styleTransform.js',
'^.+\\.js?$': 'babel-jest'
'^.+\\.(tsx|ts|js)?$': 'babel-jest'
},
watchPlugins: [
'jest-watch-typeahead/filename',
Expand Down
2 changes: 1 addition & 1 deletion packages/memoize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "emotion's memoize utility",
"main": "dist/emotion-memoize.cjs.js",
"module": "dist/emotion-memoize.esm.js",
"types": "types/index.d.ts",
"types": "dist/declarations/src/index.d.ts",
"license": "MIT",
"repository": "https://github.com/emotion-js/emotion/tree/main/packages/memoize",
"scripts": {
Expand Down
10 changes: 0 additions & 10 deletions packages/memoize/src/index.js

This file was deleted.

8 changes: 8 additions & 0 deletions packages/memoize/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function memoize<V>(fn: (arg: string) => V): (arg: string) => V {
const cache: Record<string, V> = Object.create(null)

return (arg: string) => {
if (cache[arg] === undefined) cache[arg] = fn(arg)
return cache[arg]
}
}
4 changes: 1 addition & 3 deletions packages/memoize/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
type Fn<T> = (key: string) => T

export default function memoize<T>(fn: Fn<T>): Fn<T>
export { default } from '../src'
2 changes: 1 addition & 1 deletion packages/memoize/types/tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import memoize from '@emotion/memoize'
import memoize from '../src'

// $ExpectType string[]
memoize((arg: string) => [arg])('foo')
Expand Down
3 changes: 2 additions & 1 deletion packages/memoize/types/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],

"no-unnecessary-generics": false,
"strict-export-declare-modifiers": false
"strict-export-declare-modifiers": false,
"no-default-import": false
}
}