Skip to content

Fix sass types for TS 4.7+ Node16/NodeNext module resolution#1736

Merged
Goodwine merged 1 commit intomainfrom
type-stuff
Jun 30, 2022
Merged

Fix sass types for TS 4.7+ Node16/NodeNext module resolution#1736
Goodwine merged 1 commit intomainfrom
type-stuff

Conversation

@Goodwine
Copy link
Member

Fixes #1714

@Goodwine Goodwine requested a review from nex3 June 28, 2022 20:08
Comment on lines 24 to 26
"devDependencies": {
"@types/node": "^18.0.0"
},
Copy link
Contributor

Choose a reason for hiding this comment

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

devDependencies doesn't make sense—those aren't used by packages that depend on this package, and this package.json isn't ever used for local development. I think this should just be normal dependencies.

Copy link
Contributor

@ntkme ntkme Jun 30, 2022

Choose a reason for hiding this comment

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

@nex3 @Goodwine I don't think this should be added at as dependencies, because it is the user's choice to use TS or JS. When using pure JS, we shouldn't need any types to be installed as a dependency. If this is affecting the TS compilation of this project, it should indeed be devDependencies.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wouldn't the @types/node package be downloaded regardless of whether it being declared as dependencies vs devDependencies? or do devDependencies get skipped if sass gets declared as non-dev dependency?

Copy link
Contributor

Choose a reason for hiding this comment

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

do devDependencies get skipped if sass gets declared as non-dev dependency?

This is correct, unless I'm severely misunderstanding. Sometimes it's necessary to include a dependency that's not used by some users because it's necessary for others.

Copy link

@devversion devversion Jul 1, 2022

Choose a reason for hiding this comment

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

FWIW: Node packages (even when shipping .d.ts) usually never add a dependency to just satisfy TypeScript type-checking for users. Instead:

  • Users either have to set up @types/node themselves, or the library authors place a directive implying the necessary type like: /// <reference types="node" /> into their .d.ts
  • Or, users most of the time just disable type-checking of external libraries. e..g by setting skipLibCheck: true.

Also just to make this clear: The devDependencies will never be installed for users, only for the authors of the package when e.g. yarn/npm is executed inside the folder containing the package.json.

TL;DR: Adding @types/node as a dependency is pretty uncommon. It should be removed. It's also not a big deal though and doesn't impact anyone negatively.

Copy link
Contributor

Choose a reason for hiding this comment

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

If including @types/node doesn't impact anyone negatively, and means that users can freely use the TS types without needing to manually install additional dependencies, why not include it?

Copy link
Contributor

@ntkme ntkme Jul 1, 2022

Choose a reason for hiding this comment

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

Well, this may become an addition to the reasons we get bloated node_modules.

Also, having @types/node lock to version 18 as part of dependencies is not really a good idea given that end users might want to install other versions (e.g. 16) if that is the version of node they are using. If it is devDependencies, then it does not matter as devDependencies are not installed for end users.

Copy link

@devversion devversion Jul 1, 2022

Choose a reason for hiding this comment

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

👍 @ntkme

yep, mainly for good practice of not increasing the dependency tree for people not using the TS types, which is very likely the majority here. This is peanuts in size, but a general question of best practice.

You also don't have a peer dependency/ or dependency on TypeScript itself, making guarantees with what version your types work

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, having @types/node lock to version 18 as part of dependencies is not really a good idea given that end users might want to install other versions (e.g. 16) if that is the version of node they are using.

This is a good point—we should look into making the version range here as wide as possible while still including the APIs we use (I think only Buffer?).

You also don't have a peer dependency/ or dependency on TypeScript itself, making guarantees with what version your types work

Ideally, we'd be able to specify a dependency of the form "if the downstream user has TypeScript installed, then it must have this version", but unfortunately peer dependencies will produce warnings even if the downstream user doesn't have TypeScript.

@Goodwine Goodwine requested a review from nex3 June 28, 2022 23:10
@Goodwine Goodwine merged commit 2299632 into main Jun 30, 2022
@Goodwine Goodwine deleted the type-stuff branch June 30, 2022 23:05
@devversion
Copy link

Thanks for fixing this! I just added a little comment above (which you may want to consider, or not)

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.

TypeScript types not accessible with new TS 4.7 Node16/next resolution

4 participants