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

Add typescript definitions #32

Closed
wants to merge 1 commit into from
Closed

Add typescript definitions #32

wants to merge 1 commit into from

Conversation

jsamr
Copy link

@jsamr jsamr commented Feb 17, 2020

I've been working on this for a while! It has been a very fun though hard challenge. Want to thank @fivitti for his feedbacks ;-)

resolves #24

Tested and linted typescript definitions for TS ⩾ 3.5.

Highlights

The root of typings are in types/patchinko, a requirement from dtslint.
The most important tests are located in __tests__/explicit and __tests__/overlaoded.

One big feature of those typings is to strictly enforce patchinko rules. As such, every do and don't from the readme has been carefuly tested and implemented.

Example with __tests__/overlaoded:

Screenshot_20200218_081613

__tests__/explicit:

Screenshot_20200218_081804

Limitations

One limitation of those types however, is that the returned type of a P(target, ...) call will always be typeof target. Although it could be possible, in theory, to find the resulting type from operations such as deletions ore scoped replacements, I have found this incredibly difficult and wasn't certain the compiler could follow this level of complexity and computational burden. Therefore, I thought it would be an acceptable compromise to return the target type, given the vast majority of use-cases where one want such outcome.

One who needs to circumvent those limitations just has to cast patch target to unknown:

P<unknown>(x, { foo: PS({ tada: "" }) });

Testing

Run tests with npm run test:ts which uses dtslint in the background.
It does the following:

  • Lint the sources according to DefinitelyTyped guidelines;
  • Run any test file and check for $ExpectType and $ExpectError instructions, report compilation errors;
  • Run one batch of test for each TypeScript supported version.

@jsamr jsamr requested a review from barneycarroll February 17, 2020 19:01
@jsamr jsamr force-pushed the ts branch 2 times, most recently from 15e9fac to 4c8249a Compare February 17, 2020 19:23
resolves barneycarroll#24

Tested and linted typescript definitions for TS ⩾ 3.5.
Run tests with `npm run test:ts` which uses dtslint in the background.

The root of typings are in types/patchinko, a requirement from dtslint.
The most important tests are located in __tests__/explicit and
__tests__/overlaoded.

One big feature of those typings is to strictly enforce patchinko
rules. As such, every do and don't from the readme has been carefuly
tested and implemented.

One limitation of those types however, is that the returned type of a
P(target, ...) call will always be typeof target. Although it could be
 possible, in theory, to find the resulting type from operations such
as deletions ore scoped replacements, I have found this incredibly
difficult and wasn't certain the compiler could follow this level of
complexity and computational burden. Therefore, I thought it would be
an acceptable compromise to return the target type, given the vast
majority of use-cases where one want such outcome.

On the test side, dtslint does the following:

- Lint the sources according to DefinitelyTyped guidelines;
- Run any test file and check for $ExpectType and $ExpectError
  instructions, report compilation errors;
- Run one batch of test for each TypeScript supported version.
@jsamr
Copy link
Author

jsamr commented Sep 6, 2020

@barneycarroll Anything blocking this PR getting merged?

@jsamr jsamr closed this Nov 21, 2023
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.

Please add typescript typings :)
1 participant