-
Notifications
You must be signed in to change notification settings - Fork 1
Move Rules Library to TypeScript #12
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
Move Rules Library to TypeScript #12
Conversation
src/index.ts
Outdated
| import curryToArity from "./util.js"; | ||
| import curryToArity from "./util"; | ||
|
|
||
| type Rule = { |
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.
Nice to have this is TS. 👍
Maybe as a futre step type could be refined a bit using generics with something like this:
type Rule<Facts, Result, Input> =
Plainrule<Facts, Result, Input> |
InjectedRule<Facts, Result, Input> |
TransformedRule<Facts, Result, Input> |
FirstRule<Facts, Result, Input> |
AllRule<Facts, Result, Input> |
ChainRule<Facts, Result, Input> |
IfRule<Facts, Result, Input>;
type PlainRule<Facts, Result, Input> = {
matcher: (facts: Facts, Input: input) => boolean,
action: (facts: Facts, Input: input) => Result,
}
// ... add types for other rule types here
type RuleResult<Value> = {
foundMatch: boolean;
value: Value;
};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.
Fixed it :)
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.
Awesome looks good 👍
One more small suggestion: Maybe if possible, instead of defaulting to any in the type signatures like Facts = any we could use Facts = unknown. That way we force the user to pass a type and errors will be caught quicker at build time.
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.
Agree, it needs to be done. Just worry for existing clients - we can break compile step. Suggest as next step :)
No description provided.