File: mappedTypeAsClauseRelationships.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 (47 lines) | stat: -rw-r--r-- 2,927 bytes parent folder | download | duplicates (3)
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
tests/cases/conformance/types/mapped/mappedTypeAsClauseRelationships.ts(12,9): error TS2322: Type 'T' is not assignable to type 'Modify<T>'.
tests/cases/conformance/types/mapped/mappedTypeAsClauseRelationships.ts(22,9): error TS2322: Type 'T' is not assignable to type 'ModifyInclOpt<T>'.
tests/cases/conformance/types/mapped/mappedTypeAsClauseRelationships.ts(23,9): error TS2322: Type 'T' is not assignable to type 'FilterExclOpt<T>'.
tests/cases/conformance/types/mapped/mappedTypeAsClauseRelationships.ts(24,9): error TS2322: Type 'T' is not assignable to type 'ModifyExclOpt<T>'.


==== tests/cases/conformance/types/mapped/mappedTypeAsClauseRelationships.ts (4 errors) ====
    // From original issue #45212:
    type Methods<T> = { [P in keyof T as T[P] extends Function ? P : never]: T[P] };
    type H<T> = T[keyof Methods<T>]; // Ok
    
    // `Filter<T>` only filters out some keys of `T`.
    type Filter<T> = { [P in keyof T as T[P] extends Function ? P : never]: T[P] };
    // `Modify<T>` might modify some keys of `T`.
    type Modify<T> = { [P in keyof T as P extends string? `bool${P}`: P]: T[P] };
    
    function fun<T>(val: T) {
        let x: Filter<T> = val; // Ok
        let y: Modify<T> = val; // Error
            ~
!!! error TS2322: Type 'T' is not assignable to type 'Modify<T>'.
!!! related TS2208 tests/cases/conformance/types/mapped/mappedTypeAsClauseRelationships.ts:10:14: This type parameter might need an `extends Modify<T>` constraint.
    }
    
    type FilterInclOpt<T> = { [P in keyof T as T[P] extends Function ? P : never]+?: T[P] };
    type ModifyInclOpt<T> = { [P in keyof T as P extends string? `bool${P}`: never ]+?: T[P] };
    type FilterExclOpt<T> = { [P in keyof T as T[P] extends Function ? P : never]-?: T[P] };
    type ModifyExclOpt<T> = { [P in keyof T as P extends string? `bool${P}`: never ]-?: T[P] };
    
    function fun2<T>(val: T) {
        let x: FilterInclOpt<T> = val; // Ok
        let y: ModifyInclOpt<T> = val; // Ok
            ~
!!! error TS2322: Type 'T' is not assignable to type 'ModifyInclOpt<T>'.
!!! related TS2208 tests/cases/conformance/types/mapped/mappedTypeAsClauseRelationships.ts:20:15: This type parameter might need an `extends ModifyInclOpt<T>` constraint.
        let z: FilterExclOpt<T> = val; // Error
            ~
!!! error TS2322: Type 'T' is not assignable to type 'FilterExclOpt<T>'.
!!! related TS2208 tests/cases/conformance/types/mapped/mappedTypeAsClauseRelationships.ts:20:15: This type parameter might need an `extends FilterExclOpt<T>` constraint.
        let w: ModifyExclOpt<T> = val; // Error
            ~
!!! error TS2322: Type 'T' is not assignable to type 'ModifyExclOpt<T>'.
!!! related TS2208 tests/cases/conformance/types/mapped/mappedTypeAsClauseRelationships.ts:20:15: This type parameter might need an `extends ModifyExclOpt<T>` constraint.
    }