File: mappedTypeNotMistakenlyHomomorphic.js

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-- 903 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
48
//// [mappedTypeNotMistakenlyHomomorphic.ts]
enum ABC { A, B }

type Gen<T extends ABC> = { v: T; } & (
  {
    v: ABC.A,
    a: string,
  } | {
    v: ABC.B,
    b: string,
  }
)

// Quick info: ???
//
// type Gen2<T extends ABC> = {
//    v: string;
// }
//
type Gen2<T extends ABC> = {
  [Property in keyof Gen<T>]: string;
};

// 'a' and 'b' properties required !?!?
const gen2TypeA: Gen2<ABC.A> = { v:  "I am A", a: "" };
const gen2TypeB: Gen2<ABC.B> = { v:  "I am B", b: "" };

// 'v' ???
type K = keyof Gen2<ABC.A>;

// :(
declare let a: Gen2<ABC.A>;
declare let b: Gen2<ABC.B>;
a = b;
b = a;


//// [mappedTypeNotMistakenlyHomomorphic.js]
var ABC;
(function (ABC) {
    ABC[ABC["A"] = 0] = "A";
    ABC[ABC["B"] = 1] = "B";
})(ABC || (ABC = {}));
// 'a' and 'b' properties required !?!?
var gen2TypeA = { v: "I am A", a: "" };
var gen2TypeB = { v: "I am B", b: "" };
a = b;
b = a;