-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow more cases in Tree.is (#20973)
## Description This makes 3 changes to Tree.is: 1. calling Tree.is(node, SchemaNotUsedInTreeSchema) is no longer an error. This undocumented edge case could have been problematic, and is inconsistent since it would not fire if node was not a TreeNode. 2. Tree.is now takes in ImplicitAllowedTypes, making cases like Tree.is(x, [schema.number, schema.string]) valid. THis is more performant and more concise then doing two separate checks and ORing them together. This also allows checking a node against an ImplicitAllowedTypes pulled from a FieldSchema which could be handy for some generic code. 3. The implementation of Tree.schema and Tree.is have been rewritten to not rely on flex-schema as much, and fast path non-TreeNode inputs. This should make it more maintainable and more performant. Interestingly `#2` above is the only case that couldn't be covered by `instanceof` (assuming TypeScript 5.3): we could make `instanceof` do all narrowing currently done with Tree.is, except for this new case. The presence of this case thus seems to motivate keeping `Tree.is` if for no reason other than it can support this additional pattern which `instancof` cannot.
- Loading branch information
1 parent
5a15835
commit 6dae7eb
Showing
7 changed files
with
576 additions
and
910 deletions.
There are no files selected for viewing
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
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
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
Oops, something went wrong.