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 for my packages #9
Comments
@BendingBender Would you be able to prioritize https://github.com/sindresorhus/electron-better-ipc ? I've gotten a couple of emails about doing TypeScript definitions for it. |
Will do next. |
Note to myself: clarify usage of |
@BendingBender When a function returns an array, should we make it foo(bar: string): readonly string[]; Or is it pointless? |
I wouldn't do it. I would usually expect a library to give me something I can use for every purpose, not something unnecessary limited. Otherwise I would have to cast/copy the array, this is not very nice ergonomics-wise. |
@BendingBender That's a very good point. So |
@BendingBender Would you be able to prioritize https://github.com/sindresorhus/linkify-urls and https://github.com/sindresorhus/linkify-issues? We need it for Refined GitHub. |
@BendingBender Node.js 12 is out, so would be great if you could add it to |
Will do. |
@BendingBender I know you didn't do this type definition, but would you be able to help convert it to CommonJS-style? https://github.com/chalk/chalk/blob/master/index.d.ts (It can be a breaking change as we're planning a major release there) |
Like sindresorhus/memoize#32 ? |
@bfred-it Yup |
Done. |
@BendingBender Is there any way to get VS Code and other editors to show the resolved properties? I have this https://github.com/sindresorhus/crypto-random-string/blob/32365366245e602a58a2a38c4d6fc2edd30355d7/index.d.ts#L52 and it shows up as something completely unreadable: Alternatively, a better way to write the definition. |
As far as I can see it, there is no better way to type this without giving up the exclusivity of I think that this definition would be clearer: interface BaseOptions {...}
interface TypeOptions extends BaseOptions {...}
interface CharactersOptions extends BaseOptions {...}
type Options = MergeExclusive<TypeOptions, CharactersOptions>; But it is still rendered quite ugly in the suggestion tooltip. The only other way I can think of is to use discriminated union types, but I have no idea how to do this here without hurting ergonomics: interface BaseOptions {...}
interface TypeOptions extends BaseOptions {
kind: 'types';
type?: 'hex' | 'base64' | 'url-safe';
}
interface CharactersOptions extends BaseOptions {
kind: 'characters';
characters?: string;
}
type Options = TypeOptions | CharactersOptions; // <- this one always needs the 'kind' property :-( |
You could do: interface BaseOptions { … }
interface TypeOptions extends BaseOptions {
kind: 'types';
type?: 'hex' | 'base64' | 'url-safe';
}
interface CharactersOptions extends BaseOptions {
kind: 'characters';
characters?: string;
}
// No longer needs the `kind` property:
type Options = BaseOptions | TypeOptions | CharactersOptions; |
@ExE-Boss Sorry but I've tried this before, this basically renders the type a non-discriminated union type. Thus all properties simply become optional and non-exclusive. |
Hmm, too bad. Really wish TypeScript and VS Code had a better way to handle this. |
@BendingBender Would you be able to prioritize https://github.com/sindresorhus/mimic-response ? |
I’m in the process of writing the type definitions for |
@BendingBender is helping me adding TypeScript definitions to a lot of my packages: https://github.com/search?q=user%3Asindresorhus+author%3ABendingBender+is%3Apr+typescript 🙌
We can use this space to discuss high-level things.
The text was updated successfully, but these errors were encountered: