Skip to content

Commit 054e68e

Browse files
authored
Correct TypeScript declarations (#91)
1 parent 9d1e61d commit 054e68e

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

scripts/utils.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ const writeFiles = function(options) {
153153
fs.writeFileSync(
154154
path.resolve(dir, 'index.d.ts'),
155155
type === 'Sequence_Property'
156-
? `const data: string[];\nexport default data;`
157-
: `const aliasMap: Record<number, string[]>;\nexport default aliasMap;`
156+
? `declare const data: string[];\nexport = data;`
157+
: `declare const aliasMap: Record<number, string[]>;\nexport = aliasMap;`
158158
);
159159
return;
160160
}
@@ -170,15 +170,15 @@ const writeFiles = function(options) {
170170
);
171171
fs.writeFileSync(
172172
path.resolve(dir, 'ranges.d.ts'),
173-
'import type { UnicodeRange } from "../../decode-ranges.js";\n\nconst ranges: UnicodeRange[];\nexport default ranges;\n'
173+
'import type { UnicodeRange } from "../../decode-ranges.js";\n\ndeclare const ranges: UnicodeRange[];\nexport = ranges;\n'
174174
);
175175
fs.writeFileSync(
176176
path.resolve(dir, 'regex.js'),
177177
'module.exports=/' + regenerate(codePoints).toString() + '/'
178178
);
179179
fs.writeFileSync(
180180
path.resolve(dir, 'regex.d.ts'),
181-
'declare const regex: RegExp;\nexport default regex;'
181+
'declare const regex: RegExp;\nexport = regex;'
182182
);
183183
if (codePointsSizeLt(codePoints, 10)) {
184184
const codePointsAsArray = codePoints instanceof regenerate ? codePoints.toArray() : codePoints;
@@ -205,15 +205,15 @@ const writeFiles = function(options) {
205205
);
206206
fs.writeFileSync(
207207
path.resolve(dir, 'code-points.d.ts'),
208-
`declare const codePoints: number[];\nexport default codePoints;`
208+
`declare const codePoints: number[];\nexport = codePoints;`
209209
);
210210
fs.writeFileSync(
211211
path.resolve(dir, 'symbols.js'),
212212
`module.exports=${ symbolsExports }`
213213
);
214214
fs.writeFileSync(
215215
path.resolve(dir, 'symbols.d.ts'),
216-
`declare const symbols: string[];\nexport default symbols;`
216+
`declare const symbols: string[];\nexport = symbols;`
217217
);
218218
});
219219
if (options.type == 'Bidi_Mirroring_Glyph') {
@@ -241,7 +241,7 @@ const writeFiles = function(options) {
241241
);
242242
fs.writeFileSync(
243243
path.resolve(dir, 'index.d.ts'),
244-
`const data: Map<number, string>;\nexport default data;`
244+
`declare const data: Map<number, string>;\nexport = data;`
245245
);
246246
} else {
247247
Object.keys(auxMap).forEach(function(type) {
@@ -262,7 +262,7 @@ const writeFiles = function(options) {
262262
flatRuns
263263
)})`;
264264
fs.writeFileSync(path.resolve(dir, "index.js"), output);
265-
fs.writeFileSync(path.resolve(dir, "index.d.ts"), `declare const map: Map<number, string>;\nexport default map;`);
265+
fs.writeFileSync(path.resolve(dir, "index.d.ts"), `declare const map: Map<number, string>;\nexport = map;`);
266266
});
267267
}
268268
return dirMap;

static/decode-property-map.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export default function decodePropertyMap(runs: Array<number | string>): Map<number, string>;
1+
declare function decodePropertyMap(
2+
runs: Array<number | string>,
3+
): Map<number, string>;
4+
5+
export = decodePropertyMap;

static/decode-ranges.d.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
class UnicodeRange {
2-
readonly begin: number;
3-
readonly end: number;
4-
readonly length: number;
1+
declare namespace decodeRanges {
2+
class UnicodeRange {
3+
readonly begin: number;
4+
readonly end: number;
5+
readonly length: number;
56

6-
private constructor(begin: number, end: number);
7+
private constructor(begin: number, end: number);
78

8-
keys(): Generator<number, void, unknown>;
9-
values(): Generator<string, void, unknown>;
9+
keys(): Generator<number, void, unknown>;
10+
values(): Generator<string, void, unknown>;
11+
}
12+
export type { UnicodeRange };
1013
}
1114

1215
/**
1316
* RLE + base64 decode code point ranges.
1417
*/
15-
export default function decodeRanges(input: string): UnicodeRange[];
18+
declare function decodeRanges(input: string): decodeRanges.UnicodeRange[];
1619

17-
export type { UnicodeRange };
20+
export = decodeRanges;

0 commit comments

Comments
 (0)