Move Rules Library to TypeScript#12
Merged
Aleksandr-Panin merged 7 commits intoBurdaForward:mainfrom Apr 16, 2025
Merged
Conversation
ChristophP
reviewed
Apr 14, 2025
src/index.ts
Outdated
| import curryToArity from "./util.js"; | ||
| import curryToArity from "./util"; | ||
|
|
||
| type Rule = { |
Collaborator
There was a problem hiding this comment.
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;
};
Collaborator
Author
There was a problem hiding this comment.
Fixed it :)
Collaborator
There was a problem hiding this comment.
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.
Collaborator
Author
There was a problem hiding this comment.
Agree, it needs to be done. Just worry for existing clients - we can break compile step. Suggest as next step :)
This file contains hidden or 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
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.
No description provided.