Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

fix: correct types for node16 resolution #47

Merged
merged 2 commits into from
Apr 28, 2023

Conversation

bradzacher
Copy link
Contributor

Fixes #46

  1. Adds a rollup step to generate a .d.cts file for the .cjs bundle
  2. Fixes the unnecessary type cycle in lib files

Test plan

npm pack and upload the tarball to arethetypeswrong:
image

Regarding the "masquerading" issue reported - it shouldn't cause a problem technically: arethetypeswrong/arethetypeswrong.github.io#21
Ideally the output files should be .mjs/.d.mts to be explicit, but it is okay without it (it's more of a pedantic report from my understanding).

I tested this works as expected by continuing the exmaple in #46:

$ echo "import * as foo from 'eslint-visitor-keys';\nexport default foo.shoulderror;" > test2.mts
$ echo "import * as foo from 'eslint-visitor-keys';\nexport default foo.shoulderror;" > test3.cts
$ echo "import foo = require('eslint-visitor-keys');\nexport default foo.shoulderror;" > test4.cts
$ npx tsc -b ./tsconfig.json

And it worked as expected and correctly resolved the types.

@mdjermanovic
Copy link
Member

eslint-visitor-keys.d.cts
type VisitorKeys$1 = {
    readonly [type: string]: readonly string[];
};
/**
 * @typedef {{ readonly [type: string]: ReadonlyArray<string> }} VisitorKeys
 */
/**
 * @type {VisitorKeys}
 */
declare const KEYS: VisitorKeys$1;

/**
 * Get visitor keys of a given node.
 * @param {object} node The AST node to get keys.
 * @returns {readonly string[]} Visitor keys of the node.
 */
declare function getKeys(node: object): readonly string[];
/**
 * Make the union set with `KEYS` and given keys.
 * @param {VisitorKeys} additionalKeys The additional keys.
 * @returns {VisitorKeys} The union set.
 */
declare function unionWith(additionalKeys: VisitorKeys): VisitorKeys;

type VisitorKeys = VisitorKeys$1;

export { KEYS, VisitorKeys, getKeys, unionWith };

exported KEYS will be of type VisitorKeys$1 instead of VisitorKeys. Is that okay?

@bradzacher
Copy link
Contributor Author

exported KEYS will be of type VisitorKeys$1 instead of VisitorKeys. Is that okay

Yes - the names are not required to be the same - the name is just an alias.
The types are resolved to their actual representation before they are checked by TS.

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Leaving open for others to review.

Copy link
Contributor

@snitin315 snitin315 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for contributing 🚀

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

Successfully merging this pull request may close these issues.

Bundled types fail under "node16" module
4 participants