-
Notifications
You must be signed in to change notification settings - Fork 30.4k
[color] update types for color package to 2.0 #18389
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
Conversation
types/color/index.d.ts to author (@LKay). Could you review this PR? Checklist
types/color/v1/index.d.ts Checklist
|
This PR has been open and unchanged 5 days without signoff or complaint. This will be merged by a maintainer soon if there are no objections. |
types/color/index.d.ts
Outdated
|
||
type ColorParam = string | { [param: string]: number } | number; | ||
declare class Color { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect representation of this library as you the constructors are essentially call signatures (https://github.com/Qix-/color#constructors) Since this doesnt mention that the constructors need to follow new Color you cannot declare Color as a class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sheetalkamat
But it can also use with new
. Is there any correct way to model callable class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sheetalkamat
In the previous version of type definition, new
keyword make type error, where as color library itself works well with new
keyword.
And, by its source code(https://github.com/Qix-/color/blob/master/index.js#L28), library author surely means class, not just something like callable one. (he use new
for Color
in his code)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sheetalkamat
If I read this issue correctly, there's no way to modeling callable class in TypeScript, isn't it?
Then I believe class is better than interface, i.e., I want more concrete reason for revision.
Or, is interface better than class? Then, could you give me some reasoning related with those?
@sheetalkamat I fix it. Now |
b(): number; | ||
b(val: number): Color; | ||
keyword(): string; | ||
keyword(val: string): Color; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am looking at this and wondering why does val have to be string. https://github.com/Qix-/color/blob/master/index.js#L232 wouldnt it mean that val can be of type ColorParam? and not just string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sheetalkamat
It's just because I try to match return type of getter and parameter type of (immutable) setter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ailrun I am not familiar with the API and since the PR is open for more than 7 days, I will merge it if you think this is correct parameter type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sheetalkamat At least I believe, using keyword
function with any other parameter than css keywords is somehow insane thing, so I argue that this one is a valid type.
* create types for color package * Fix Color class to interface
Please fill in this template.
npm run lint package-name
(ortsc
if notslint.json
is present).Select one of these and delete the others:
If changing an existing definition:
tslint.json
containing{ "extends": "dtslint/dt.json" }
.