This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When looking a bit into eslint-community/eslint-utils#150 I felt that the types of this module, which is used by that module, was quite generic – so I stepped into that rabbit hole and looked into if it could be made more tightly typed, and this is the result.
Is it strictly needed for eslint-community/eslint-utils#150 ? Not really.
Would it be a waste to throw it away just because of that? Yes, I think so.
Exports
KEYS
is now typed with exactly the structure that it has, thanks to using@satisfy
and@type {const}
. So if I accessKEYS.ArrayPattern
it has the type ofreadonly ["elements"]
getKeys()
is now typed so that it returns a filtered union of string literals, based on the keys of the object sent in, rather than always justreadonly string[]
. It still returnsreadonly string[]
when given an input that's egRecord<string, any>
unionWith()
now uses the extendedVisitorKeys
to returnVisitorKeys
with the keys set to union of the keys inadditionalKeys
andVisitorKeyTypes
(the keys ofKEYS
). It still returns plainVisitorKeys
when given a generic input likeVisitorKeys
Types
VisitorKeys
is now a generic that can be used to create a more narrow type, likeVisitorKeys<VisitorKeyTypes, import("estree").Node | import("estree-jsx").Node>
would roughly be the same as whatKEYS
has (but less precise since keys gets all property types). Without any parameters given it works likeVisitorKeys
did previously.VisitorKeyTypes
, that represents all keys fromKEYS
FilteredKeysOf<T>
, the type equivalent to the filtering thatgetKeys()
doesAdditional notes
readonly
keyword in all places where it causes linting troubles (Parsing errors withreadonly
jsdoc-type-pratt-parser/jsdoc-type-pratt-parser#164). It got replaced with eitherReadonly<>
orReadonlyArray<>
.eslint-disable jsdoc/valid-types
typescript
/tsd
androllup
modules to get it to eg. recognize thelib: ['es2022']
in thetsconfig.json
Closing notes
I realize that some of the changes proposed here might be seen as a bit extreme when it comes to juggling TypeScript types in JSDoc definitions – and if some are considered too extreme I can try to pull them out. But I think it's nothing too crazy in there.