Skip to content
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

Typescript Definitions and Usage Examples #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jmfirth
Copy link

@jmfirth jmfirth commented Feb 12, 2018

This pull request adds annotated TypeScript definitions and usage examples. Changes include:

  • TypeScript definitions, strictly defined, with comments.
  • TypeScript usage examples in strict mode showing inferred use with commented types, with invalid usage examples.
  • Package script to validate TypeScript definitions and usage examples instrumented to run concurrent to existing unit tests.

Notably, the definitions were created to prevent invalid usage. So, the following constraints were encoded in the type system:

  • Filter properties should not be used when canFilter is not set to true. (example)
  • onChange is properly typed based on value of simpleValues. (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 of canFilter and simpleValues 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+.

@jakezatecky
Copy link
Owner

Thanks for the PR. I'll look into merging this then when the March release comes along. I have effectively no experience with TypeScript, but I have no issue adding support definitions to help other developers use this library.

@nystromb
Copy link

nystromb commented May 1, 2018

I am working on a project that could use this. Are there still plans for this to be released?

@Kimahriman
Copy link

If the maintainer doesn't have TypeScript experience it makes more sense to put these in DefinitelyTyped. Unless @jakezatecky wants to learn about it and start maintaining the TypeScript definitions

@jakezatecky jakezatecky added this to the v2.0.0 milestone Jan 31, 2019
@jakezatecky jakezatecky modified the milestones: v2.0.0, v2.1.0 May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants