@sidex/types 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,169 @@
1
+ import Nominal from "./nominal";
2
+ /**
3
+ * A string.
4
+ *
5
+ * We do not need `Nominal` here because any `string` is a valid Sidex string.
6
+ */
7
+ export type String = string;
8
+ /**
9
+ * A Base64-encoded sequence of bytes.
10
+ */
11
+ export type Bytes = Nominal<string, "::std::builtins::bytes">;
12
+ /**
13
+ * An 8-bit signed integer.
14
+ */
15
+ export type I8 = Nominal<number, "::std::builtins::i8">;
16
+ /**
17
+ * Convert any number to an 8-bit signed integer.
18
+ *
19
+ * @param x The number to convert.
20
+ * @returns The 8-bit signed integer.
21
+ */
22
+ export declare function toI8(x: number): I8;
23
+ /**
24
+ * Check whether the provided number is an 8-bit signed integer.
25
+ *
26
+ * @param x The number to check.
27
+ * @returns Indicates whether the number is an 8-bit signed integer.
28
+ */
29
+ export declare function isI8(x: number): x is I8;
30
+ /**
31
+ * A 16-bit signed integer.
32
+ */
33
+ export type I16 = Nominal<number, "::std::builtins::i16">;
34
+ /**
35
+ * Convert any number to an 16-bit signed integer.
36
+ *
37
+ * @param x The number to convert.
38
+ * @returns The 16-bit signed integer.
39
+ */
40
+ export declare function toI16(x: number): I16;
41
+ /**
42
+ * Check whether the provided number is an 16-bit signed integer.
43
+ *
44
+ * @param x The number to check.
45
+ * @returns Indicates whether the number is an 16-bit signed integer.
46
+ */
47
+ export declare function isI16(x: number): x is I16;
48
+ /**
49
+ * A 32-bit signed integer.
50
+ */
51
+ export type I32 = Nominal<number, "::std::builtins::i32">;
52
+ /**
53
+ * A 64-bit signed integer.
54
+ */
55
+ export type I64 = Nominal<string, "::std::builtins::i64">;
56
+ /**
57
+ * A signed integer.
58
+ */
59
+ export type SignedInt = I8 | I16 | I32 | I64;
60
+ /**
61
+ * An 8-bit unsigned integer.
62
+ */
63
+ export type U8 = Nominal<number, "::std::builtins::u8">;
64
+ /**
65
+ * Convert any number to an 8-bit unsigned integer.
66
+ *
67
+ * @param x The number to convert.
68
+ * @returns The 8-bit unsigned integer.
69
+ */
70
+ export declare function toU8(x: number): U8;
71
+ /**
72
+ * Check whether the provided number is an 8-bit unsigned integer.
73
+ *
74
+ * @param x The number to check.
75
+ * @returns Indicates whether the number is an 8-bit unsigned integer.
76
+ */
77
+ export declare function isU8(x: number): x is U8;
78
+ /**
79
+ * A 16-bit unsigned integer.
80
+ */
81
+ export type U16 = Nominal<number, "::std::builtins::u16">;
82
+ /**
83
+ * Convert any number to an 16-bit unsigned integer.
84
+ *
85
+ * @param x The number to convert.
86
+ * @returns The 16-bit unsigned integer.
87
+ */
88
+ export declare function toU16(x: number): U16;
89
+ /**
90
+ * Check whether the provided number is an 16-bit unsigned integer.
91
+ *
92
+ * @param x The number to check.
93
+ * @returns Indicates whether the number is an 16-bit unsigned integer.
94
+ */
95
+ export declare function isU16(x: number): x is U16;
96
+ /**
97
+ * A 32-bit unsigned integer.
98
+ */
99
+ export type U32 = Nominal<number, "::std::builtins::u32">;
100
+ /**
101
+ * A 64-bit unsigned integer.
102
+ */
103
+ export type U64 = Nominal<string, "::std::builtins::u64">;
104
+ /**
105
+ * An unsigned integer.
106
+ */
107
+ export type UnsignedInt = U8 | U16 | U32 | U64;
108
+ /**
109
+ * An integer.
110
+ */
111
+ export type Int = SignedInt | UnsignedInt;
112
+ /**
113
+ * An index.
114
+ */
115
+ export type Idx = Nominal<number, "::std::builtins::idx">;
116
+ /**
117
+ * Convert any number to an index.
118
+ *
119
+ * @param x The number to convert.
120
+ * @returns The index.
121
+ */
122
+ export declare function toIdx(x: number): Idx;
123
+ /**
124
+ * Check whether the provided number is an index.
125
+ *
126
+ * @param x The number to check.
127
+ * @returns Indicates whether the number is an index.
128
+ */
129
+ export declare function isIdx(x: number): x is Idx;
130
+ /**
131
+ * A 32-bit floating point number.
132
+ */
133
+ export type F32 = Nominal<number | "+Infinity" | "-Infinity" | "NaN", "f32">;
134
+ /**
135
+ * A 64-bit floating point number.
136
+ */
137
+ export type F64 = Nominal<number | "+Infinity" | "-Infinity" | "NaN", "f64">;
138
+ /**
139
+ * A floating point number.
140
+ */
141
+ export type Float = F32 | F64;
142
+ /**
143
+ * A numeric value.
144
+ */
145
+ export type Numeric = Int | Idx | Float;
146
+ /**
147
+ * A boolean.
148
+ */
149
+ export type Bool = boolean;
150
+ /**
151
+ *
152
+ */
153
+ export type Unit = null;
154
+ /**
155
+ * A sequence.
156
+ */
157
+ export type Sequence<T> = T[];
158
+ /**
159
+ * A map represented as a sequence of key-value pairs.
160
+ */
161
+ export type EntriesMap<K, V> = [K, V][];
162
+ /**
163
+ * A map represented as an object.
164
+ */
165
+ export type ObjectMap<K extends string, V> = {
166
+ [key in K]?: V;
167
+ };
168
+ export declare function entries<K extends string, V>(map: ObjectMap<K, V>): [K, V][];
169
+ export declare function entries<K, V>(map: EntriesMap<K, V>): [K, V][];
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.entries = exports.isIdx = exports.toIdx = exports.isU16 = exports.toU16 = exports.isU8 = exports.toU8 = exports.isI16 = exports.toI16 = exports.isI8 = exports.toI8 = void 0;
4
+ /**
5
+ * Convert any number to an 8-bit signed integer.
6
+ *
7
+ * @param x The number to convert.
8
+ * @returns The 8-bit signed integer.
9
+ */
10
+ function toI8(x) {
11
+ return (((x | 0) << 24) >> 24);
12
+ }
13
+ exports.toI8 = toI8;
14
+ /**
15
+ * Check whether the provided number is an 8-bit signed integer.
16
+ *
17
+ * @param x The number to check.
18
+ * @returns Indicates whether the number is an 8-bit signed integer.
19
+ */
20
+ function isI8(x) {
21
+ return toI8(x) === x;
22
+ }
23
+ exports.isI8 = isI8;
24
+ /**
25
+ * Convert any number to an 16-bit signed integer.
26
+ *
27
+ * @param x The number to convert.
28
+ * @returns The 16-bit signed integer.
29
+ */
30
+ function toI16(x) {
31
+ return (((x | 0) << 16) >> 16);
32
+ }
33
+ exports.toI16 = toI16;
34
+ /**
35
+ * Check whether the provided number is an 16-bit signed integer.
36
+ *
37
+ * @param x The number to check.
38
+ * @returns Indicates whether the number is an 16-bit signed integer.
39
+ */
40
+ function isI16(x) {
41
+ return toI16(x) === x;
42
+ }
43
+ exports.isI16 = isI16;
44
+ /**
45
+ * Convert any number to an 8-bit unsigned integer.
46
+ *
47
+ * @param x The number to convert.
48
+ * @returns The 8-bit unsigned integer.
49
+ */
50
+ function toU8(x) {
51
+ return (x && 0xff);
52
+ }
53
+ exports.toU8 = toU8;
54
+ /**
55
+ * Check whether the provided number is an 8-bit unsigned integer.
56
+ *
57
+ * @param x The number to check.
58
+ * @returns Indicates whether the number is an 8-bit unsigned integer.
59
+ */
60
+ function isU8(x) {
61
+ return toU8(x) === x;
62
+ }
63
+ exports.isU8 = isU8;
64
+ /**
65
+ * Convert any number to an 16-bit unsigned integer.
66
+ *
67
+ * @param x The number to convert.
68
+ * @returns The 16-bit unsigned integer.
69
+ */
70
+ function toU16(x) {
71
+ return (x && 0xffff);
72
+ }
73
+ exports.toU16 = toU16;
74
+ /**
75
+ * Check whether the provided number is an 16-bit unsigned integer.
76
+ *
77
+ * @param x The number to check.
78
+ * @returns Indicates whether the number is an 16-bit unsigned integer.
79
+ */
80
+ function isU16(x) {
81
+ return toU16(x) === x;
82
+ }
83
+ exports.isU16 = isU16;
84
+ /**
85
+ * Convert any number to an index.
86
+ *
87
+ * @param x The number to convert.
88
+ * @returns The index.
89
+ */
90
+ function toIdx(x) {
91
+ // Remove the sign and truncate the number to 32 bits.
92
+ return (Math.abs(x) | 0);
93
+ }
94
+ exports.toIdx = toIdx;
95
+ /**
96
+ * Check whether the provided number is an index.
97
+ *
98
+ * @param x The number to check.
99
+ * @returns Indicates whether the number is an index.
100
+ */
101
+ function isIdx(x) {
102
+ return toIdx(x) === x;
103
+ }
104
+ exports.isIdx = isIdx;
105
+ /**
106
+ * Convert any numeric value to a JavaScript number.
107
+ *
108
+ * @param x The numeric value to convert.
109
+ * @returns The JavaScript number.
110
+ */
111
+ function toNumber(x) {
112
+ switch (typeof x) {
113
+ case "number":
114
+ return x;
115
+ case "string":
116
+ switch (x) {
117
+ case "+Infinity":
118
+ return +Infinity;
119
+ case "-Infinity":
120
+ return -Infinity;
121
+ case "NaN":
122
+ return NaN;
123
+ default:
124
+ return Number.parseInt(x);
125
+ }
126
+ }
127
+ }
128
+ /**
129
+ * The entries of the map.
130
+ *
131
+ * @param map
132
+ * @returns
133
+ */
134
+ function entries(map) {
135
+ if (Array.isArray(map)) {
136
+ return map;
137
+ }
138
+ else {
139
+ return Object.entries(map);
140
+ }
141
+ }
142
+ exports.entries = entries;
143
+ function getIndexMap(map) {
144
+ if (map.hasOwnProperty(__indexMap)) {
145
+ return map[__indexMap];
146
+ }
147
+ else {
148
+ const map = new Map();
149
+ map.forEach(([key, _], index) => map.set(key, index));
150
+ return map;
151
+ }
152
+ }
153
+ // export function get<K, V>(map: AnyMap<K, V>, key: K): V | undefined {
154
+ // if (Array.isArray(map)) {
155
+ // const index = getIndexMap(map).get(key)
156
+ // return index === undefined ? undefined : (map[index] as [K, V])[1]
157
+ // } else {
158
+ // return (map as ObjectMap<any, V>)[key]
159
+ // }
160
+ // }
161
+ // export function set<K, V>(map: AnyMap<K, V>, key: K, value: V) {
162
+ // if (Array.isArray(map)) {
163
+ // const indexMap = getIndexMap(map)
164
+ // const existingIndex = indexMap.get(key)
165
+ // if (existingIndex !== undefined) {
166
+ // map[existingIndex] = [key, value]
167
+ // } else {
168
+ // const index = map.length
169
+ // map.push([key, value])
170
+ // indexMap.set(key, index)
171
+ // }
172
+ // } else {
173
+ // return (map as ObjectMap<any, V>)[key]
174
+ // }
175
+ // }
176
+ //# sourceMappingURL=builtins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builtins.js","sourceRoot":"","sources":["../src/builtins.ts"],"names":[],"mappings":";;;AAmBA;;;;;GAKG;AACH,SAAgB,IAAI,CAAC,CAAS;IAC5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E,8BAA8B;AAC9B,wCAAwC;AACxC,8CAA8C;AAC9C,yCAAyC;AACzC,0CAA0C;AAC1C,eAAe;AACf,iCAAiC;AACjC,+BAA+B;AAC/B,iCAAiC;AACjC,QAAQ;AACR,aAAa;AACb,6CAA6C;AAC7C,MAAM;AACN,IAAI"}
@@ -0,0 +1,2 @@
1
+ export * as builtins from "./builtins";
2
+ export type { Nominal, Structural } from "./nominal";
package/dist/index.js ADDED
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.builtins = void 0;
27
+ exports.builtins = __importStar(require("./builtins"));
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAsC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Unique symbol used for nominal types.
3
+ */
4
+ declare const SIDEX_PATH_SYMBOL: unique symbol;
5
+ type N<P extends string> = {
6
+ [SIDEX_PATH_SYMBOL]: {
7
+ [key in P]: null;
8
+ };
9
+ };
10
+ /**
11
+ * A nominal type based on `T` and identified by it's Sidex path `P`.
12
+ */
13
+ export type Nominal<T, P extends string> = T & N<P>;
14
+ /**
15
+ * The structural type of a nominal type `T`.
16
+ */
17
+ export type Structural<T> = T extends undefined ? undefined : T extends boolean ? boolean : T extends null ? null : T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends Array<infer U> ? U[] : T extends (...args: infer Args) => infer Return ? (...args: Args) => Return : Omit<T, typeof SIDEX_PATH_SYMBOL>;
18
+ export default Nominal;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=nominal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nominal.js","sourceRoot":"","sources":["../src/nominal.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -2,17 +2,30 @@
2
2
  "name": "@sidex/types",
3
3
  "author": "Silitics GmbH <info@silitics.com>",
4
4
  "license": "(MIT or Apache-2.0)",
5
- "version": "0.0.4",
5
+ "version": "0.0.6",
6
6
  "description": "",
7
- "main": "src/index.ts",
8
- "types": "./src/index.ts",
7
+ "files": [
8
+ "src",
9
+ "dist"
10
+ ],
11
+ "main": "./dist/index.ts",
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/index.js",
15
+ "types": "./dist/index.d.js"
16
+ },
17
+ "./*": {
18
+ "import": "./dist/*.js",
19
+ "types": "./dist/*.d.ts"
20
+ }
21
+ },
22
+ "types": "./dist/index.d.ts",
9
23
  "keywords": [],
10
24
  "devDependencies": {
11
25
  "typescript": "^4.8.4"
12
26
  },
13
27
  "scripts": {
14
- "doc": "typedoc lib/index.ts",
15
- "tsc": "tsc",
28
+ "build": "tsc",
16
29
  "test": "echo \"Error: no test specified\" && exit 1"
17
30
  }
18
31
  }
package/src/builtins.ts CHANGED
@@ -242,10 +242,9 @@ export type EntriesMap<K, V> = [K, V][]
242
242
  */
243
243
  export type ObjectMap<K extends string, V> = { [key in K]?: V }
244
244
 
245
- /**
246
- * A map.
247
- */
248
- export type AnyMap<K, V> = K extends string ? ObjectMap<K, V> : EntriesMap<K, V>
245
+ export function entries<K extends string, V>(map: ObjectMap<K, V>): [K, V][]
246
+
247
+ export function entries<K, V>(map: EntriesMap<K, V>): [K, V][]
249
248
 
250
249
  /**
251
250
  * The entries of the map.
@@ -253,7 +252,7 @@ export type AnyMap<K, V> = K extends string ? ObjectMap<K, V> : EntriesMap<K, V>
253
252
  * @param map
254
253
  * @returns
255
254
  */
256
- export function entries<K, V>(map: AnyMap<K, V>): [K, V][] {
255
+ export function entries<K, V>(map: any): any {
257
256
  if (Array.isArray(map)) {
258
257
  return map
259
258
  } else {
@@ -273,27 +272,27 @@ function getIndexMap<K, V>(map: EntriesMap<K, V>): Map<K, number> {
273
272
  }
274
273
  }
275
274
 
276
- export function get<K, V>(map: AnyMap<K, V>, key: K): V | undefined {
277
- if (Array.isArray(map)) {
278
- const index = getIndexMap(map).get(key)
279
- return index === undefined ? undefined : (map[index] as [K, V])[1]
280
- } else {
281
- return (map as ObjectMap<any, V>)[key]
282
- }
283
- }
284
-
285
- export function set<K, V>(map: AnyMap<K, V>, key: K, value: V) {
286
- if (Array.isArray(map)) {
287
- const indexMap = getIndexMap(map)
288
- const existingIndex = indexMap.get(key)
289
- if (existingIndex !== undefined) {
290
- map[existingIndex] = [key, value]
291
- } else {
292
- const index = map.length
293
- map.push([key, value])
294
- indexMap.set(key, index)
295
- }
296
- } else {
297
- return (map as ObjectMap<any, V>)[key]
298
- }
299
- }
275
+ // export function get<K, V>(map: AnyMap<K, V>, key: K): V | undefined {
276
+ // if (Array.isArray(map)) {
277
+ // const index = getIndexMap(map).get(key)
278
+ // return index === undefined ? undefined : (map[index] as [K, V])[1]
279
+ // } else {
280
+ // return (map as ObjectMap<any, V>)[key]
281
+ // }
282
+ // }
283
+
284
+ // export function set<K, V>(map: AnyMap<K, V>, key: K, value: V) {
285
+ // if (Array.isArray(map)) {
286
+ // const indexMap = getIndexMap(map)
287
+ // const existingIndex = indexMap.get(key)
288
+ // if (existingIndex !== undefined) {
289
+ // map[existingIndex] = [key, value]
290
+ // } else {
291
+ // const index = map.length
292
+ // map.push([key, value])
293
+ // indexMap.set(key, index)
294
+ // }
295
+ // } else {
296
+ // return (map as ObjectMap<any, V>)[key]
297
+ // }
298
+ // }
package/src/nominal.ts CHANGED
@@ -3,12 +3,13 @@
3
3
  */
4
4
  declare const SIDEX_PATH_SYMBOL: unique symbol
5
5
 
6
+ // This type improves error messages.
7
+ type N<P extends string> ={ [SIDEX_PATH_SYMBOL]: { [key in P]: null } }
8
+
6
9
  /**
7
10
  * A nominal type based on `T` and identified by it's Sidex path `P`.
8
11
  */
9
- export type Nominal<T, P extends string> = T & {
10
- [SIDEX_PATH_SYMBOL]: { [key in P]: null }
11
- }
12
+ export type Nominal<T, P extends string> = T & N<P>
12
13
 
13
14
  /**
14
15
  * The structural type of a nominal type `T`.
package/tsconfig.json DELETED
@@ -1,63 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2017",
4
- "module": "commonjs",
5
-
6
- // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
7
- // "declarationMap": true, /* Create sourcemaps for d.ts files. */
8
- // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
9
- // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
10
- // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
11
- // "outDir": "./", /* Specify an output folder for all emitted files. */
12
- // "removeComments": true, /* Disable emitting comments. */
13
- // "noEmit": true, /* Disable emitting files from a compilation. */
14
- // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
15
- // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
16
- // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
17
- // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
18
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
19
- // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
20
- // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
21
- // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
22
- // "newLine": "crlf", /* Set the newline character for emitting files. */
23
- // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
24
- // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
25
- // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
26
- // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
27
- // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
28
- // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
29
-
30
- /* Interop Constraints */
31
- "isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */,
32
- // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
33
- "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
34
- // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
35
- "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
36
-
37
- /* Type Checking */
38
- "strict": true /* Enable all strict type-checking options. */,
39
- // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
40
- // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
41
- // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
42
- // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
43
- // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
44
- // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
45
- // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
46
- // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
47
- // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
48
- // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
49
- // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
50
- // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
51
- // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
52
- "noUncheckedIndexedAccess": true /* Add 'undefined' to a type when accessed using an index. */,
53
- // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
54
- // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
55
- // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
56
- // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
57
-
58
- /* Completeness */
59
- // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
60
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
61
- },
62
- "files": ["src/index.ts"]
63
- }