File: arrayCast.errors.txt

package info (click to toggle)
node-typescript 2.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 203,952 kB
  • ctags: 52,987
  • sloc: sh: 11; makefile: 5
file content (16 lines) | stat: -rw-r--r-- 1,064 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
tests/cases/compiler/arrayCast.ts(3,23): error TS2352: Type '{ foo: string; }[]' cannot be converted to type '{ id: number; }[]'.
  Type '{ foo: string; }' is not comparable to type '{ id: number; }'.
    Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'.


==== tests/cases/compiler/arrayCast.ts (1 errors) ====
    // Should fail. Even though the array is contextually typed with { id: number }[], it still
    // has type { foo: string }[], which is not assignable to { id: number }[].
    <{ id: number; }[]>[{ foo: "s" }];
                          ~~~~~~~~
!!! error TS2352: Type '{ foo: string; }[]' cannot be converted to type '{ id: number; }[]'.
!!! error TS2352:   Type '{ foo: string; }' is not comparable to type '{ id: number; }'.
!!! error TS2352:     Object literal may only specify known properties, and 'foo' does not exist in type '{ id: number; }'.
    
    // Should succeed, as the {} element causes the type of the array to be {}[]
    <{ id: number; }[]>[{ foo: "s" }, {}];