-
Notifications
You must be signed in to change notification settings - Fork 10
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
Create TypeScript typings #5
Comments
assign me. |
Hi @jinkya, all yours! |
Hi @jinkya, just wanted to follow up. Can you still take this up? If not, wanted to leave it open for others before the end of the month. Thanks! |
I'd like to take this up |
Can I work on this with @daniel-shuy |
Sorry @AnshMishra2001, I'm almost done, just left with the test cases. I'll link the PR here once its ready if you want to review it. |
@bluepnume I have a question: static try<X, Y, C : mixed, A : $ReadOnlyArray<mixed>>(method : (...args : $ReadOnlyArray<mixed>) => (ZalgoPromise<X> | Y), context? : C, args? : A) : ZalgoPromise<X | Y> { Should the type for I'm wondering if I should define it in TypeScript as: static try<X, C, A extends readonly any[]>(method: (...args: readonly any[]) => ZalgoPromise<X>, context?: C, args?: A): ZalgoPromise<X>;
static try<Y, C, A extends readonly any[]>(method: (...args: readonly any[]) => Y, context?: C, args?: A): ZalgoPromise<Y>; or: static try<X, C, A extends readonly any[]>(method: (...args: A) => ZalgoPromise<X>, context?: C, args?: A): ZalgoPromise<X>;
static try<Y, C, A extends readonly any[]>(method: (...args: A) => Y, context?: C, args?: A): ZalgoPromise<Y>; Or is this done intentionally so that it can be called with partial arguments? eg. ZalgoPromise.try((...args: [boolean, number, string]) => {
console.error(args);
}, this, [false]); // pass less arguments than defined parameters if so, then I can define it as: static try<X, C, A extends readonly any[]>(method: (...args: A) => ZalgoPromise<X>, context?: C, args?: Partial<A>): ZalgoPromise<X>;
static try<Y, C, A extends readonly any[]>(method: (...args: A) => Y, context?: C, args?: Partial<A>): ZalgoPromise<Y>; |
Also, another question: Do we need to support mixed ZalgoPromise.resolve(0)
.catch(error => {
if (error) {
return `${error}`;
} else {
return ZalgoPromise.resolve(false);
}
}); Currently catch<X, Y>(onError : (error : mixed) => ZalgoPromise<X> | Y) : ZalgoPromise<X | Y> { The above works in Flow because type parameters default to This means that: catch<X, Y>(onError: (error: any) => ZalgoPromise<X> | Y): ZalgoPromise<X | Y>; in TypeScript, when called without explicitly specifying type parameters, eg. ZalgoPromise.resolve(0)
.catch(error => `${error}`); would infer To avoid having to explicitly specifying type parameters, function overloading can be used instead of union types, eg. catch<X>(onError: (error: any) => ZalgoPromise<X>): ZalgoPromise<X>;
catch<Y>(onError: (error: any) => Y): ZalgoPromise<Y>; This however means that the |
Created a PR at DefinitelyTyped/DefinitelyTyped#56179 |
Thanks @daniel-shuy! |
An issue that I discovered while working on this is that the <!-- UMD -->
<script src="zalgo-promise.js"></script>
<script>
new ZalgoPromise.ZalgoPromise( ... );
</script> // CommonJS
var ZalgoPromise = require('zalgo-promise');
new ZalgoPromise.ZalgoPromise( ... ); See https://stackblitz.com/edit/typescript-zdsko6?file=index.ts |
@mstuart @bluepnume should I hold off merging the PR for you to review once its approved? |
@mstuart @bluepnume the PR has been approved, should I go ahead and merge it? |
Since there's no reply I've gone ahead and merged it. The type definitions are now released in npm (@types/zalgo-promise) |
This project isn't written in TypeScript, but many TypeScript users would like to use published typings. For this issue, create TypeScript typings that cover the exported functions, and contribute it back to DefinitelyTyped!
This issue is great for someone who wants to learn more about TypeScript!
The text was updated successfully, but these errors were encountered: