Skip to content

Commit 52fa531

Browse files
authored
feat(typescript): migrate to typescript (#56)
* feat(typescript): migrate to typescript * chore(lint): fix lint-diff * chore(ts): improve ts * chore(typescript): update * chore(typescript): update * chore(ts): update * chore: tidy * feat(typescript): pass through ParameterTypes to returned function BREAKING CHANGE: this changes the getKey parameters 😭 * chore(deps): update deps * feat(ts): add callback values, noissue * chore: rm editorconfig * chore(lint): fix lint * chore(ts): remove deprecation warnings BREAKING CHANGES: Change in the `options.getKey(...args)` => `options.getKeys(args)` args is contained in first parameter.
1 parent 35efefe commit 52fa531

File tree

10 files changed

+2823
-339
lines changed

10 files changed

+2823
-339
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ workflows:
99
jobs:
1010
- node/test
1111
- release/npm_and_github:
12+
build_command: npm run build
1213
context:
1314
- org-global
1415
- github-release

.editorconfig

Lines changed: 0 additions & 17 deletions
This file was deleted.

.eslintrc.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"root": true,
3-
"extends": ["5app", "prettier"],
4-
"plugins": ["prettier"],
3+
"parser": "@typescript-eslint/parser",
4+
"plugins": ["@typescript-eslint", "prettier"],
5+
"extends": ["5app", "plugin:@typescript-eslint/recommended", "prettier"],
6+
"ignorePatterns": ["dist/"],
57
"rules": {
68
"prettier/prettier": "error"
79
}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
.DS_Store
3-
.nyc_output
3+
.nyc_output
4+
dist/

example.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint-disable no-console */
2+
import memoize from './src/index.js';
3+
4+
// Define a function which returns an object
5+
type ProfileId = number;
6+
interface Profile {
7+
id: ProfileId;
8+
name: string;
9+
age: number;
10+
}
11+
12+
async function getMyProfile(id: ProfileId): Promise<Profile> {
13+
return {
14+
id,
15+
name: 'Andrew',
16+
age: 100,
17+
};
18+
}
19+
20+
const memoProfile = memoize(getMyProfile, {
21+
useCached(param) {
22+
return param.timestamp ? param.timestamp > Date.now() : false;
23+
},
24+
getKey(param) {
25+
return param[0];
26+
},
27+
});
28+
29+
const resp = await memoProfile(123);
30+
31+
console.log(resp?.id);

0 commit comments

Comments
 (0)