-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add .decorator()
method
#61
Conversation
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
It should be clearly documented that it's only for TypeScript consumers. I'm also not sure about the "mixin" naming. "mixin" is a pretty overloaded term and it doesn't exactly fit here. |
@sindresorhus > I'm also not sure about the "mixin" naming. See how it's done in emittery. What should we call it instead? |
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
It's called that there because the decorator actually "mixes in". That's not about the decorator itself.
Any suggestions? |
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
@sindresorhus |
Yeah, I cannot think of something better than that. |
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
Where did the build statuses go? |
@sindresorhus Are you at the point of switching to Github Actions for all of your projects? |
@Richienb Still interested in finishing this? I noticed it's still marked as a draft PR and tests are failing. |
Yes - most the errors look to be TypeScript compilation errors so I'll get to fixing them |
>( | ||
options: Options<FunctionToMemoize, CacheKeyType> = {} | ||
) => ( | ||
target: any, |
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 don't think there's a way to avoid this being any
.
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.
Shouldn't it be:
target: any, | |
target: FunctionToMemoize, |
?
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.
target
refers to the object that the function lives in. const input: FunctionToMemoize = target[propertyKey]
.
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.
Shouldn't it at least be object
then to ensure undefined
and null
are not the target? Also, I generally prefer unknown
over any
whenever possible.
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.
object
isn't allowed by xo
which wants it to be Record<string, unknown>
which doesn't work either because a class is not an plain object.
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.
Not using object
is just a general rule. You shouldn't use any
either, ideally. But sometimes we need exceptions. Just use an eslint-ignore
comment.
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.
As soon as I change any
to object
, the compiler throws because {}
can't be indexed by a string
.
If I try to use generics with {target: Target, propertyKey: keyof Target}
, the compiler (possible due to a bug) is instead unable to resolve a target properly so it always falls back to unknown
, making propertyKey
resolve to never
.
It looks like setting it to anything else, is nearly impossible.
>( | ||
options: Options<FunctionToMemoize, CacheKeyType> = {} | ||
) => ( | ||
target: any, |
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.
Shouldn't it be:
target: any, | |
target: FunctionToMemoize, |
?
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
Fixes: #60
// @sindresorhus @fregante