File: indexSignatureOfTypeUnknownStillRequiresIndexSignature.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (18 lines) | stat: -rw-r--r-- 941 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
tests/cases/compiler/indexSignatureOfTypeUnknownStillRequiresIndexSignature.ts(9,3): error TS2345: Argument of type '{ name: string; age: number; }[]' is not assignable to parameter of type '{ [x: string]: unknown; }'.
  Index signature for type 'string' is missing in type '{ name: string; age: number; }[]'.


==== tests/cases/compiler/indexSignatureOfTypeUnknownStillRequiresIndexSignature.ts (1 errors) ====
    declare function f<T extends unknown = unknown>(x: { [x: string]: T }): T;
    
    var stooges = [
      { name: "moe", age: 40 },
      { name: "larry", age: 50 },
      { name: "curly", age: 60 }
    ];
    
    f(stooges); // Should throw
      ~~~~~~~
!!! error TS2345: Argument of type '{ name: string; age: number; }[]' is not assignable to parameter of type '{ [x: string]: unknown; }'.
!!! error TS2345:   Index signature for type 'string' is missing in type '{ name: string; age: number; }[]'.