-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
BREAKING CHANGE: rewrite the package using Typescript #144
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Conflicts: # package.json
# Conflicts: # src/Model.js # tests/dummy/data/post.js # tests/dummy/data/postEmbed.ts # tests/dummy/data/postsEmbed.js # tests/dummy/models/Post.js # tests/model.test.ts # yarn.lock
# Conflicts: # README.md
This commit remove conditional types feature from static methods. Due to limitations in typescript Generic Classes, this change was needed in order to fix compilation of declaration files.
# Conflicts: # src/utils.js
Outdated. Work continue on branch/next-major |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The package was rewritten using Typescript, with full types support and conditional types for responses. There are no breaking changes for JavaScript applications.
One of my goals when doing this rewrite was to have a precise type checking for responses.
As some responses might be wrapped in "data", I made the Model class a
Generic Class, which accepts two boolean arguments in order to conditionally change
the returned type from responses.
See Conditional Types for more information.
The first argument should be set to
true
if the collection is wrapped in "data".The second argument should be set to
true
if the model is wrapped in "data".For example, we can have a Post model that has a wrapped collection, but an unwrapped model:
The backend response like this:
Then we have the correct type checking:
If all of your models follows the same structure, you can define the arguments in your Base model class, abstracting this configuration from your models.
Note that I wasn't able to make precise type checkings for Static methods due to a limitation on Generic Classes:
See Type Parameters in Static Members for more information.
Based on #104 by @alvaro-canepa
Closes #108
TODO
dev