File: typeSatisfaction_propertyNameFulfillment.types

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 (50 lines) | stat: -rw-r--r-- 1,383 bytes parent folder | download | duplicates (2)
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
49
50
=== tests/cases/conformance/expressions/typeSatisfaction/typeSatisfaction_propertyNameFulfillment.ts ===
type Keys = 'a' | 'b' | 'c' | 'd';
>Keys : "a" | "b" | "c" | "d"

const p = {
>p : { a: number; b: string; x: number; }
>{    a: 0,    b: "hello",    x: 8 // Should error, 'x' isn't in 'Keys'} satisfies Record<Keys, unknown> : { a: number; b: string; x: number; }
>{    a: 0,    b: "hello",    x: 8 // Should error, 'x' isn't in 'Keys'} : { a: number; b: string; x: number; }

    a: 0,
>a : number
>0 : 0

    b: "hello",
>b : string
>"hello" : "hello"

    x: 8 // Should error, 'x' isn't in 'Keys'
>x : number
>8 : 8

} satisfies Record<Keys, unknown>;

// Should be OK -- retain info that a is number and b is string
let a = p.a.toFixed();
>a : string
>p.a.toFixed() : string
>p.a.toFixed : (fractionDigits?: number) => string
>p.a : number
>p : { a: number; b: string; x: number; }
>a : number
>toFixed : (fractionDigits?: number) => string

let b = p.b.substring(1);
>b : string
>p.b.substring(1) : string
>p.b.substring : (start: number, end?: number) => string
>p.b : string
>p : { a: number; b: string; x: number; }
>b : string
>substring : (start: number, end?: number) => string
>1 : 1

// Should error even though 'd' is in 'Keys'
let d = p.d;
>d : any
>p.d : any
>p : { a: number; b: string; x: number; }
>d : any