-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
Use non-nullable types in vscode.d.ts #6907
Comments
depends on TypeStrong/typedoc#234 |
@egamma @dbaeumer Looking for some guidance here. Challenge is that many of the providers define method return types ala // option 1a, inline
interface CodeLensProvider {
provideCodeLenses(document: TextDocument, token: CancellationToken): CodeLens[] | undefined | null | Thenable<CodeLens[] | undefined | null>
}
// option 1b, inline but even more verbose
interface CodeLensProvider {
provideCodeLenses(document: TextDocument, token: CancellationToken): CodeLens[] | undefined | null | Thenable<CodeLens[]> | Thenable<undefined> | Thenable<null>
}
// option 1c, one type for null or undefined
type Nully = null | undefined;
interface CodeLensProvider {
provideCodeLenses(document: TextDocument, token: CancellationToken): CodeLens[] | Nully | Thenable<CodeLens[] | Nully>
}
// option 2, generic result-type
type Result<T> = T | undefined | null | Thenable<T | undefined | null>
interface CodeLensProvider {
provideCodeLenses(document: TextDocument, token: CancellationToken): Result<CodeLens[]>
}
// option 3, generic nullable-type
type Nullable<T> = T | undefined | null;
interface CodeLensProvider {
provideCodeLenses(document: TextDocument, token: CancellationToken): Nullable<CodeLens[]> | Thenable<Nullable<CodeLens[]>>
} Options 2 and 3 have the advantage that they can be applied to all providers and make a shorter method signature. On the downside that add another indirection and might make things harder to understand... Tho, also option 1 isn't exactly easy to read and understand. I'd prefer option 1c |
@jrieken hard call: I would actually go for 2.) and name it ProviderResult. Using Nullable makes it bound to nullable. If TS comes up with another feature we might need to change the signature again. With ProviderResult we might be able to simple change that type then. |
+1 for option 2 ( |
I'd combine 2 and 3, each a different problem in itself, but composable with each other: type Maybe<T> = T | undefined | null;
type Result<T> = Maybe<T> | Thenable<Maybe<T>>;
interface CodeLensProvider {
provideCodeLenses(document: TextDocument, token: CancellationToken): Result<T>;
} |
Wanted to suggest |
type Eventually<T> = Maybe<T> | Thenable<Maybe<T>>; 😄 |
Keeping the two concepts separate might be easier to read and would allow for more variants of reuse: type Maybe<T> = T | undefined | null;
type Eventually<T> = T | Thenable<T>;
interface CodeLensProvider {
provideCodeLenses(document: TextDocument, token: CancellationToken): Eventually<Maybe<CodeLens[]>>;
} |
Just as a reminder - We aren't just targeting TypeScript-ninjas but also folks that haven't seen a type annotation before. From my experience, even things like OR-types aren't fully understood/made use of so I am not so sure if a 'double nested generic or-type' is the way to go. |
+1 for option 3
IMO, this makes it API more readable for all kinds of users with out many references. In fact, Nullable is a bit straight so that user do not need to look for its reference. |
+1 for option 3 then (don't hurt the ninjas!) |
+1 for option 2 with a different name for Reasons:
|
@Microsoft/vscode I am looking for volunteers that migrate their extensions to use |
@jrieken how do I migrate my extension? |
@weinand - to program against the latest API do the following:
note tho that this no also depends on TypeScript 2.0 |
@jrieken done. That was easy. |
@ramya-rao-a This was meant for |
TypeScript will introduce support for strict null check and explicit handling of
null
andundefined
- microsoft/TypeScript#7140. This is a great opportunity for us to make the API more explicit and hopefully a chance to prevent programming errors. Parts of the API can move from jsdoc comments into type annotations. For instance, the active editor is declared like this today:and we can move jsdoc type info back into code like so
The text was updated successfully, but these errors were encountered: