-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andy Hanson
committed
Nov 9, 2018
1 parent
d4973d5
commit fa63536
Showing
27 changed files
with
213 additions
and
83 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
tests/cases/compiler/arrayReduce.ts(10,2): error TS2322: Type '{ kind: string; value: number; }' is not assignable to type 'Operation'. | ||
Types of property 'kind' are incompatible. | ||
Type 'string' is not assignable to type '"add" | "subtract"'. | ||
|
||
|
||
==== tests/cases/compiler/arrayReduce.ts (1 errors) ==== | ||
function toStrings(arr: ReadonlyArray<object>): string[] { | ||
return arr.reduce((acc, obj) => { | ||
acc.push(obj.toString()); | ||
return acc; | ||
}, [] as string[]); | ||
} | ||
|
||
interface Operation { readonly kind: "add" | "subtract"; readonly value: number; } | ||
function add(arr: ReadonlyArray<Operation>): Operation { | ||
return arr.reduce(({ value }, { kind, value: v }) => { | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
return { kind: "add", value: kind === "add" ? value + v : value - v }; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
}, { kind: "add", value: 5 }); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2322: Type '{ kind: string; value: number; }' is not assignable to type 'Operation'. | ||
!!! error TS2322: Types of property 'kind' are incompatible. | ||
!!! error TS2322: Type 'string' is not assignable to type '"add" | "subtract"'. | ||
} | ||
|
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Oops, something went wrong.