forked from web-platform-dx/web-features
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
149 lines (134 loc) · 3.46 KB
/
types.ts
File metadata and controls
149 lines (134 loc) · 3.46 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* eslint-disable @typescript-eslint/no-unused-vars */
// Quicktype produces definitions that are correct, but not as narrow or
// well-named as hand-written type definition might produce. This module takes
// the Quicktype-generated types as renames or modifies the types to be somewhat
// nicer to work with in TypeScript.
import type {
BaselineEnum as BaselineHighLow,
BrowserData,
Browsers,
Discouraged,
GroupData,
Kind,
FeatureData as QuicktypeMonolithicFeatureData,
Status as QuicktypeStatus,
StatusHeadline as QuicktypeStatusHeadline,
WebFeaturesData as QuicktypeWebFeaturesData,
Release,
SnapshotData,
Support,
} from "./types.quicktype";
// Passthrough types
export type {
BaselineHighLow,
BrowserData,
Browsers,
Discouraged,
GroupData,
Release,
SnapshotData,
Support,
};
export interface Status extends QuicktypeStatus {
baseline: false | BaselineHighLow;
}
export interface SupportStatus extends QuicktypeStatusHeadline {
baseline: false | BaselineHighLow;
}
// These are "tests" for our type definitions.
const badQuicktypeStatusHeadline: QuicktypeStatusHeadline = {
baseline: true, // This is an improper value in our actual published data
support: {},
};
const badQuicktypeStatus: QuicktypeStatus = badQuicktypeStatusHeadline;
const badSupportStatus: SupportStatus = {
// This validates that we're actually overriding Quicktype (and correctly). If
// `baseline: true` ever becomes possible in the `SupportStatus`, then
// TypeScript will complain about the next line.
// @ts-expect-error
baseline: true,
support: {},
};
const badStatus: Status = {
// @ts-expect-error
baseline: true,
support: {},
};
const goodSupportStatus: QuicktypeStatusHeadline | SupportStatus = {
baseline: false,
support: {},
};
export interface WebFeaturesData extends Pick<
QuicktypeWebFeaturesData,
"browsers" | "groups" | "snapshots"
> {
features: {
[key: string]: FeatureData | FeatureMovedData | FeatureSplitData;
};
}
export type FeatureData = { kind: "feature" } & Required<
Pick<
QuicktypeMonolithicFeatureData,
"description_html" | "description" | "name" | "spec" | "status"
>
> &
Partial<
Pick<
QuicktypeMonolithicFeatureData,
"caniuse" | "compat_features" | "discouraged" | "group" | "snapshot"
>
>;
const goodFeatureData: FeatureData = {
kind: "feature",
name: "Test",
description: "Hi",
description_html: "Hi",
spec: [""],
snapshot: [""],
group: [""],
caniuse: [""],
discouraged: {
reason: "",
reason_html: "",
according_to: [""],
alternatives: [""],
},
status: {
baseline: false,
support: {},
},
};
type FeatureRedirectData = { kind: Exclude<Kind, "feature"> } & Required<
Pick<QuicktypeMonolithicFeatureData, "redirect_target" | "redirect_targets">
>;
export interface FeatureMovedData extends Omit<
FeatureRedirectData,
"redirect_targets"
> {
kind: "moved";
}
const goodFeatureMovedData: FeatureMovedData = {
kind: "moved",
redirect_target: "",
};
const badFeatureMovedData: FeatureMovedData = {
kind: "moved",
// @ts-expect-error
redirect_targets: ["", ""],
};
export interface FeatureSplitData extends Omit<
FeatureRedirectData,
"redirect_target"
> {
kind: "split";
}
const goodFeatureSplitData: FeatureSplitData = {
kind: "split",
redirect_targets: ["", ""],
};
const badFeatureSplitData: FeatureSplitData = {
kind: "split",
// @ts-expect-error
redirect_target: "",
};
export type BrowserIdentifier = keyof Browsers;