diff --git a/.changeset/warm-ducks-provide.md b/.changeset/warm-ducks-provide.md new file mode 100644 index 0000000..e34d632 --- /dev/null +++ b/.changeset/warm-ducks-provide.md @@ -0,0 +1,5 @@ +--- +'@ssecd/jkn': patch +--- + +fix types diff --git a/src/index.ts b/src/index.ts index 0904484..c89c39d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,10 +6,6 @@ import { ICare } from './icare.js'; import { PCare } from './pcare/index.js'; import { VClaim } from './vclaim/index.js'; -type JKNResponseType = NonNullable< - 'response' extends keyof Awaited> ? Awaited>['response'] : never ->; - export default class JKN extends Fetcher { private readonly cache = new CachedApi(this); @@ -39,9 +35,17 @@ export default class JKN extends Fetcher { } } +type JKNResponseType = NonNullable< + // @ts-expect-error T[K] will always a method of class T + 'response' extends keyof Awaited> ? Awaited>['response'] : never +>; + +// cannot use built-in Parameters type helper with class type that return from method eg. VClaim[T][K] +type MethodParameters = T extends (...args: infer P) => unknown ? P : never; + export type AntreanResponse = JKNResponseType; -export type AntreanParams = Parameters; +export type AntreanParams = MethodParameters; export type VClaimResponse< T extends keyof VClaim, // @@ -51,7 +55,7 @@ export type VClaimResponse< export type VClaimParams< T extends keyof VClaim, // K extends keyof VClaim[T] -> = Parameters; +> = MethodParameters; export type ApotekResponse< T extends keyof Apotek, // @@ -61,4 +65,8 @@ export type ApotekResponse< export type ApotekParams< T extends keyof Apotek, // K extends keyof Apotek[T] -> = Parameters; +> = MethodParameters; + +export type ICareResponse = JKNResponseType; + +export type ICareParams = MethodParameters; diff --git a/tsconfig.json b/tsconfig.json index 89fa37e..452b031 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,7 @@ "resolveJsonModule": true, "moduleResolution": "NodeNext", "strict": true, - "module": "esnext", + "module": "NodeNext", "target": "esnext", "lib": ["esnext", "DOM"], "outDir": "dist",