Created
November 4, 2022 16:10
-
-
Save wycats/f8d86917ca53dbe80fcf2b25f59e351f to your computer and use it in GitHub Desktop.
Revisions
-
wycats created this gist
Nov 4, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,110 @@ # October 25, 2022 to November 4, 2022 ## Generics around missingness ```ts function Name<S extends string | undefined>(name: S): S { return name; } ``` But this doesn't work: ```ts function Name<S extends string | undefined>(name?: S): S { return name; // ~~~~ Type 'T | undefined' is not assignable to type 'T' } Name(); // type is string | undefined ``` ## Object Literal Overloads ```ts const x = { foo(a: string) => string, foo(a: number) => string, foo(a: string | number) => a { return a; } }; ``` ## Can't auto-infer getters ```ts class X { // this can be auto-inferred foo() { return 1; } // this can't get foo() { return 1; } } ``` ## `import()` auto-completes to `ImportAssertions` ```ts type X = import| // ^ if I type `(` here, it completes to `ImportAssertions` ``` This is because `(` is a commit character, and "accept suggestions on commit characters" is on by default. ## `split()` treats the first element of the array as nullable ```ts const [a]: [string] = "".split(" "); // ~~~ Type 'string[]' is not assignable to type '[string]'. // Target requires 1 element(s) but source may have fewer ``` ## Unlisted Property Narrowing is Still Not Quite Right ```ts declare const x: Record<string, string>; if ("a" in x) { const y: string = x["a"]; // ~ Type 'string | undefined' is not assignable to type 'string'. } ``` I have `exactOptionalPropertyTypes` and `noUncheckedIndexedAccess` on. I can see why this is happening, but with `exactOptionalPropertyTypes` on, I would expect the type of `x["a"]` to be `string` after the `in` check. ## `override` is Great for Jump-to-Definition, But Doesn't Exist for `implements` ```ts interface Hello { hello(): string; } class X implements Hello { override hello() { // ~~~~~ This member cannot have an 'override' modifier because // its containing class 'X' does not extend another class return "hello"; } } ``` What about this? ```ts interface Hello { hello(): string; } class X implements Hello { implements hello() { return "hello"; } } ```