File: genericMappedTypeAsClause.errors.txt

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (48 lines) | stat: -rw-r--r-- 2,863 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
tests/cases/compiler/genericMappedTypeAsClause.ts(11,36): error TS2322: Type 'string' is not assignable to type 'number'.
tests/cases/compiler/genericMappedTypeAsClause.ts(14,11): error TS2322: Type 'number' is not assignable to type 'MappedModel<T>'.
tests/cases/compiler/genericMappedTypeAsClause.ts(15,11): error TS2322: Type 'string' is not assignable to type 'MappedModel<T>'.
tests/cases/compiler/genericMappedTypeAsClause.ts(16,11): error TS2322: Type 'number[]' is not assignable to type 'MappedModel<T>'.
tests/cases/compiler/genericMappedTypeAsClause.ts(17,11): error TS2322: Type 'boolean' is not assignable to type 'MappedModel<T>'.
tests/cases/compiler/genericMappedTypeAsClause.ts(18,34): error TS2322: Type '{ a: string; b: number; }' is not assignable to type 'MappedModel<T>'.
  Object literal may only specify known properties, and 'a' does not exist in type 'MappedModel<T>'.
tests/cases/compiler/genericMappedTypeAsClause.ts(19,11): error TS2322: Type 'undefined' is not assignable to type 'MappedModel<T>'.


==== tests/cases/compiler/genericMappedTypeAsClause.ts (7 errors) ====
    type Model = {
        a: string;
        b: number;
    };
    
    type MappedModel<Suffix extends string> = {
        [K in keyof Model as `${K}${Suffix}`]: Model[K];
    };
    
    const foo1: MappedModel<'Foo'> = { aFoo: 'test', bFoo: 42 };
    const foo2: MappedModel<'Foo'> = { bFoo: 'bar' };  // Error
                                       ~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
!!! related TS6500 tests/cases/compiler/genericMappedTypeAsClause.ts:6:43: The expected type comes from property 'bFoo' which is declared here on type 'MappedModel<"Foo">'
    
    function f1<T extends string>() {
        const x1: MappedModel<T> = 42;  // Error
              ~~
!!! error TS2322: Type 'number' is not assignable to type 'MappedModel<T>'.
        const x2: MappedModel<T> = 'test';  // Error
              ~~
!!! error TS2322: Type 'string' is not assignable to type 'MappedModel<T>'.
        const x3: MappedModel<T> = [1, 2, 3];  // Error
              ~~
!!! error TS2322: Type 'number[]' is not assignable to type 'MappedModel<T>'.
        const x4: MappedModel<T> = false;  // Error
              ~~
!!! error TS2322: Type 'boolean' is not assignable to type 'MappedModel<T>'.
        const x5: MappedModel<T> = { a: 'bar', b: 42 };  // Error
                                     ~~~~~~~~
!!! error TS2322: Type '{ a: string; b: number; }' is not assignable to type 'MappedModel<T>'.
!!! error TS2322:   Object literal may only specify known properties, and 'a' does not exist in type 'MappedModel<T>'.
        const x6: MappedModel<T> = undefined;  // Error
              ~~
!!! error TS2322: Type 'undefined' is not assignable to type 'MappedModel<T>'.
    }