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

The MockerProxyRoute type does not work for strictNullChecks #124

Closed
ikatyang opened this issue Aug 13, 2020 · 7 comments
Closed

The MockerProxyRoute type does not work for strictNullChecks #124

ikatyang opened this issue Aug 13, 2020 · 7 comments

Comments

@ikatyang
Copy link

Version: 2.3.0

Steps to reproduce:

mkdir mocker-api-repro-MockerProxyRoute-strictNullChecks
cd mocker-api-repro-MockerProxyRoute-strictNullChecks
npm init -y
npm install typescript mocker-api
echo '{"compilerOptions":{"strictNullChecks":true,"allowSyntheticDefaultImports":true}}' > tsconfig.json
echo 'import {} from "mocker-api"' > index.ts
npx tsc
node_modules/mocker-api/lib/index.d.ts:36:5 - error TS2411: Property '_proxy' of type 'MockerOption | undefined' is not assignable to string index type 'MockerResult'.

36     _proxy?: MockerOption;
       ~~~~~~


Found 1 error.
jaywcjlove added a commit that referenced this issue Aug 13, 2020
@jaywcjlove
Copy link
Owner

@ikatyang Reference example.

@ikatyang
Copy link
Author

#125 (comment) can also reproduce the issue here.

@ikatyang
Copy link
Author

Here's the patch I used to workaround this issue:

diff --git a/lib/index.d.ts b/lib/index.d.ts
index 2edca13a3814452a8170cb9cc0f856dd0d65553b..4511678106ca1111d9836f816012c76db8f4ab17 100644
--- a/lib/index.d.ts
+++ b/lib/index.d.ts
@@ -26,7 +26,7 @@ export declare type MockerResult = string | number | Array<any> | Record<string,
  * }
  * ```
  */
-export interface MockerProxyRoute extends Record<string, MockerResult> {
+export type MockerProxyRoute = Record<string, MockerResult> & {
     /**
      * This is the option parameter setting for apiMocker
      * Priority processing.
      * apiMocker(app, path, option)
      * {@link MockerOption}
      */
     _proxy?: MockerOption;
 }

@jaywcjlove
Copy link
Owner

@ikatyang Change the interface to type?

@ikatyang
Copy link
Author

Yes, the issue here is that undefined | MockerOption does not satisfy its index signature MockerResult, using intersection type can bypass this limitation.

jaywcjlove added a commit that referenced this issue Aug 13, 2020
@jaywcjlove
Copy link
Owner

@ikatyang Upgrade + [email protected]

@ikatyang
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants