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

fix: adjust type to remove need for @types/lodash #362

Merged
merged 1 commit into from
Jan 18, 2021

Conversation

G-Rath
Copy link
Contributor

@G-Rath G-Rath commented Jan 11, 2021

Currently TS errors for this package if @types/lodash is not installed:

node_modules/json-schema-to-typescript/dist/src/types/JSONSchema.d.ts:1:23 - error TS2688: Cannot find type definition file for 'lodash'.

1 /// <reference types="lodash" />
                        ~~~~~~

node_modules/json-schema-to-typescript/dist/src/types/JSONSchema.d.ts:86:95 - error TS7016: Could not find a declaration file for module 'lodash'. '/c/Users/G-Rath/workspace/projects-oss/webhooks/node_modules/json-schema-to-typescript/node_modules/lodash/lodash.js'
 implicitly has an 'any' type.
  Try `npm i --save-dev @types/lodash` if it exists or add a new declaration (.d.ts) file containing `declare module 'lodash';`

86 export declare const getRootSchema: ((schema: LinkedJSONSchema) => LinkedJSONSchema) & import("lodash").MemoizedFunction;

I actually thought this was because of #361 but it's not - not sure why it didn't error in the past on the same project.

Originally I was going to add @types/lodash to dependencies, but realised I could explicitly type the export to make it not needed.

Copy link
Owner

@bcherny bcherny left a comment

Choose a reason for hiding this comment

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

Hey, thanks for the contribution! Could we add the dependency on @types/lodash instead? Otherwise, without a way to add a test for this, this is likely to silently regress in the future (eg. next time someone refactors this function, and chooses to remove the unnecessary type annotation).

@G-Rath
Copy link
Contributor Author

G-Rath commented Jan 18, 2021

@bcherny ugh that's a very good point 🤦‍♂️

A possible way to guard against that could be to export the memoize from a local file with a wrapper and comment explaining why, so that everything would use that memoize.

@G-Rath G-Rath force-pushed the add-@types-lodash-dependency branch from b7ac52b to ff937b6 Compare January 18, 2021 18:16
@G-Rath G-Rath requested a review from bcherny January 18, 2021 18:16
@G-Rath
Copy link
Contributor Author

G-Rath commented Jan 18, 2021

(btw I've made some PRs to update the browser version to the latest major 🙂)

Copy link
Owner

@bcherny bcherny left a comment

Choose a reason for hiding this comment

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

Thanks for updating!

@bcherny bcherny merged commit 0470aee into bcherny:master Jan 18, 2021
@bcherny
Copy link
Owner

bcherny commented Jan 18, 2021

Published 10.1.3

@utajum
Copy link

utajum commented Aug 30, 2024

I am seeing this error with versions >= 15

Versions below 15 work fine

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

Successfully merging this pull request may close these issues.

4 participants