Refine TypeScript types and address type resolution issues #65
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.
Currently, when using TypeScript, type resolution will fail if the
moduleResolution
compiler option in tsconfig.json is set to nodenext, and thetype
property in a project's package.json is set to anything other thanmodule
. This is due to thenodenext
module resolution strategy, which requires explicit definition of the TypeScripttypes
location for both ESMimport
and CJSrequire
exports in package.json, and will ignore the previously used top-leveltypes
package.json property.Additionally, due to deficiencies in TypeScript's understanding of inherited class static methods, chained class static method calls following calls to the inherited
extend
method in theUser
andGroup
resource classes lose their correct target class. This causes all types to fall back to using types declared on the baseResource
class, which are not intended to be used directly.Furthermore, when working with resources whose schemas have been extended, there is currently no easy means of describing the expected shape of the
instance
argument or return value shape of ingress/egress handler implementations. This means they cannot easily be type-checked.This change adds explicit
types
fields, pointing to the common type definition file, for each of the ESM/CJS exports in the SCIMMY package.json file (fixes #63 pt. 1). JSDoc type annotations have also been updated to explicitly declare the staticextend
method on theUser
andGroup
resource classes, and the static ingress/egress methods have been made generic, accepting a single type parameter describing the shape of instance and return values (fixes #63 pt. 2). An additional type annotation,SCIMMY.Types.Schema.Extended
, has also been added to facilitate working with resources whose schemas have been extended (fixes #63 pt. 3). More refined type annotations have also been sprinkled throughout, where previously properties or parameters were declared as being of type "any".