Last active
August 23, 2024 08:33
-
-
Save ralph/c33ffd92b6b67751dbb06efb88282031 to your computer and use it in GitHub Desktop.
Revisions
-
ralph revised this gist
Jun 21, 2023 . No changes.There are no files selected for viewing
-
ralph revised this gist
Jun 21, 2023 . No changes.There are no files selected for viewing
-
ralph created this gist
Jun 21, 2023 .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,12 @@ src/test.ts:10:39 - error TS18049: 'item' is possibly 'null' or 'undefined'. 10 strings.forEach((item) => console.log(item.id, item.label)) ~~~~ src/test.ts:10:48 - error TS18049: 'item' is possibly 'null' or 'undefined'. 10 strings.forEach((item) => console.log(item.id, item.label)) ~~~~ Found 2 errors in the same file, starting at: src/test.ts 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,10 @@ const stringsAndNull = [ { id: 1, label: 'foo' }, { id: 2, label: 'bar' }, null, { id: 3, label: 'test' }, undefined, { id: 3, label: 'lol' }, ] const strings = stringsAndNull.filter((item) => item != null) strings.forEach((item) => console.log(item.id, item.label)) 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,7 @@ src/test.ts:10:17 - error TS2345: Argument of type '(item: { id: number; label: string;}) => void' is not assignable to parameter of type '(value: { id: number; label: string; } | null | undefined, index: number, array: ({ id: number; label: string; } | null | undefined)[]) => void'. Types of parameters 'item' and 'value' are incompatible. Type '{ id: number; label: string; } | null | undefined' is not assignable to type '{ id: number; label: string; }'. Type 'undefined' is not assignable to type '{ id: number; label: string; }'. 10 strings.forEach((item: { id: number, label: string}) => console.log(item.id, item.label)) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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,10 @@ const stringsAndNull = [ { id: 1, label: 'foo' }, { id: 2, label: 'bar' }, null, { id: 3, label: 'test' }, undefined, { id: 3, label: 'lol' }, ] const strings = stringsAndNull.filter((item) => item != null) strings.forEach((item: { id: number, label: string }) => console.log(item.id, item.label))