Typescript Definitions and Usage Examples #37
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.
This pull request adds annotated TypeScript definitions and usage examples. Changes include:
Notably, the definitions were created to prevent invalid usage. So, the following constraints were encoded in the type system:
canFilter
is not set totrue
. (example)onChange
is properly typed based on value ofsimpleValues
. (example)Unfortunately of these constraints depend on a feature called conditional types which is slated to be released along with TypeScript 2.8 in March. This is why
[email protected]
was added as a development dependency. I tried to type these constraints in other ways, such as combining the property groups as intersections of discriminated unions, or using mapped types to map the value ofcanFilter
andsimpleValues
to an index I could leverage to provide types for other properties, but I was not able to satisfy TypeScript 2.7.1 and the conditions properly.Obviously this isn't something you'll want to ship today, and the TypeScript semver range will need to be adjusted when 2.8 is released, but they will be here for then. If these constraints were unwanted, or otherwise removed, these definitions would be compatible with (I believe) at least TypeScript 2+.