Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
tweak a bunch of stuff
  • Loading branch information
Andarist committed Aug 14, 2021
commit 9ab2cf148ddd7574c56d1937febc037db8623b5c
2 changes: 1 addition & 1 deletion .changeset/loud-hairs-approve.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@emotion/weak-memoize': minor
---

Convert to TypeScript and emit definitions based on the code
Source code has been migrated to TypeScript. From now on type declarations will be emitted based on that, instead of being hand-written.
3 changes: 1 addition & 2 deletions packages/memoize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
},
"files": [
"src",
"dist",
"types/*.d.ts"
"dist"
],
"browser": {
"./dist/emotion-memoize.cjs.js": "./dist/emotion-memoize.browser.cjs.js",
Expand Down
3 changes: 1 addition & 2 deletions packages/weak-memoize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
},
"files": [
"src",
"dist",
"types/*.d.ts"
"dist"
],
"browser": {
"./dist/emotion-weak-memoize.cjs.js": "./dist/emotion-weak-memoize.browser.cjs.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/weak-memoize/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ let weakMemoize = function <Arg extends object, Return>(
let cache = new WeakMap<Arg, Return>()
return (arg: Arg) => {
if (cache.has(arg)) {
// Cast to `Return` because we just checked that the cache `has` it
// Use non-null assertion because we just checked that the cache `has` it
// This allows us to remove `undefined` from the return value
return cache.get(arg) as Return
return cache.get(arg)!
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, TIL about the non-null assertion, thank you @Andarist

}
let ret = func(arg)
cache.set(arg, ret)
Expand Down
3 changes: 3 additions & 0 deletions packages/weak-memoize/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// TypeScript Version: 2.2

export { default } from '../src'
3 changes: 2 additions & 1 deletion packages/weak-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
}
}