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

Refine TypeScript types and address type resolution issues #65

Merged
merged 9 commits into from
Jan 6, 2025

Conversation

sleelin
Copy link
Collaborator

@sleelin sleelin commented Jan 6, 2025

Currently, when using TypeScript, type resolution will fail if the moduleResolution compiler option in tsconfig.json is set to nodenext, and the type property in a project's package.json is set to anything other than module. This is due to the nodenext module resolution strategy, which requires explicit definition of the TypeScript types location for both ESM import and CJS require exports in package.json, and will ignore the previously used top-level types 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 the User and Group resource classes lose their correct target class. This causes all types to fall back to using types declared on the base Resource 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 static extend method on the User and Group 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".

@sleelin sleelin added bug Something isn't working documentation Improvements or additions to documentation labels Jan 6, 2025
@sleelin sleelin added this to the 1.3.2 milestone Jan 6, 2025
@sleelin sleelin self-assigned this Jan 6, 2025
@sleelin sleelin linked an issue Jan 6, 2025 that may be closed by this pull request
@sleelin sleelin merged commit 061aef1 into main Jan 6, 2025
3 checks passed
@sleelin sleelin deleted the issue/63-typescript-type-fixes branch January 6, 2025 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Development

Successfully merging this pull request may close these issues.

Typescript types problems
1 participant