You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript will introduce support for strict null check and explicit handling of null and undefined - 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:
/**
* The currently active editor or `undefined`. ...
*/
export let activeTextEditor: TextEditor;
and we can move jsdoc type info back into code like so
/**
* The currently...
*/
export let activeTextEditor: TextEditor | undefined;
Erich Gamma (@egamma)Dirk Bäumer (@dbaeumer) Looking for some guidance here. Challenge is that many of the providers define method return types ala Foo | Thenable<Foo>. The current behaviour (spec'd in jsdoc) is that they are allowed to return undefined or null sync or async from with in the promise. That results in the following, very verbose, strict-null-aware signature:
// option 1a, inlineinterfaceCodeLensProvider{provideCodeLenses(document: TextDocument,token: CancellationToken): CodeLens[]|undefined|null|Thenable<CodeLens[]|undefined|null>}// option 1b, inline but even more verboseinterfaceCodeLensProvider{provideCodeLenses(document: TextDocument,token: CancellationToken): CodeLens[]|undefined|null|Thenable<CodeLens[]>|Thenable<undefined>|Thenable<null>}// option 1c, one type for null or undefinedtypeNully=null|undefined;interfaceCodeLensProvider{provideCodeLenses(document: TextDocument,token: CancellationToken): CodeLens[]|Nully|Thenable<CodeLens[]|Nully>}// option 2, generic result-typetypeResult<T>=T|undefined|null|Thenable<T|undefined|null>interfaceCodeLensProvider{provideCodeLenses(document: TextDocument,token: CancellationToken): Result<CodeLens[]>}// option 3, generic nullable-typetypeNullable<T>=T|undefined|null;interfaceCodeLensProvider{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
Johannes Rieken (@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.
Wanted to suggest Optional<T> but actually like Maybe<T> even better.
+1 for option 3 with Maybe<T>.
I'd rather not combine it with 2, too many types, and, especially, 'Result' is too general.
Johannes Rieken (@jrieken) done. That was easy.
But I have to set "strictNullChecks": truein my tsconfig.json so that the compiler actually checks for this.
Activity
jrieken commentedon Oct 10, 2016
depends on TypeStrong/typedoc#234
jrieken commentedon Nov 3, 2016
Erich Gamma (@egamma) Dirk Bäumer (@dbaeumer) Looking for some guidance here. Challenge is that many of the providers define method return types ala
Foo | Thenable<Foo>. The current behaviour (spec'd in jsdoc) is that they are allowed to returnundefinedornullsync or async from with in the promise. That results in the following, very verbose, strict-null-aware signature: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
dbaeumer commentedon Nov 4, 2016
Johannes Rieken (@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.
bpasero commentedon Nov 7, 2016
+1 for option 2 (
generic result-type)joaomoreno commentedon Nov 7, 2016
I'd combine 2 and 3, each a different problem in itself, but composable with each other:
aeschli commentedon Nov 7, 2016
Wanted to suggest
Optional<T>but actually likeMaybe<T>even better.+1 for option 3 with
Maybe<T>.I'd rather not combine it with 2, too many types, and, especially, 'Result' is too general.
joaomoreno commentedon Nov 7, 2016
😄
chrmarti commentedon Nov 7, 2016
Keeping the two concepts separate might be easier to read and would allow for more variants of reuse:
9 remaining items
jrieken commentedon Nov 23, 2016
Andre Weinand (@weinand) - to program against the latest API do the following:
package.jsonfileengine.vscodeproperty to*npm run postinstall(assuming you have thevscodemodule as dev-dependency)note tho that this no also depends on TypeScript 2.0
weinand commentedon Nov 23, 2016
Johannes Rieken (@jrieken) done. That was easy.
But I have to set
"strictNullChecks": truein my tsconfig.json so that the compiler actually checks for this.ramya-rao-a commentedon Dec 5, 2016
Johannes Rieken (@jrieken) The test item #16515 is linked here, but the test item does not have anything on non-nullable types.
jrieken commentedon Dec 6, 2016
Ramya Rao (@ramya-rao-a) This was meant for
verification-neededbut I have special verifier in mind: those that have already updated their extensions to use strict null checks. I have Matt Bierner (@mjbvz) (ts/js) and João Moreno (@joaomoreno) (git exploration) in mind