Skip to content

Commit abcc196

Browse files
committed
fix: improve types
Signed-off-by: 90dy <90dy@proton.me>
1 parent 2d2055b commit abcc196

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.6.0",
2+
"version": "0.6.1",
33
"author": "90dy",
44
"license": "MIT",
55
"workspace": [

src/core/mod.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,12 @@ export const LANGUAGES: Record<string, LanguageDefinition> = {
300300
},
301301
};
302302

303-
type Template<T> = string & TemplateClass<T>;
303+
type Template<Type, Data> = string & TemplateClass<Type, Data>;
304304

305-
class TemplateClass<T = unknown> extends String {
305+
class TemplateClass<Type, Data = unknown> extends String {
306306
public readonly type: string;
307307
public readonly raw: string;
308-
public data?: T;
308+
public data?: Data;
309309
private error?: Error;
310310
private parser?: (text: string) => unknown;
311311
constructor(
@@ -360,36 +360,36 @@ class TemplateClass<T = unknown> extends String {
360360
return this.valueOf();
361361
}
362362

363-
indent(value: false | number): Template<T> {
364-
return new TemplateClass<T>(
363+
indent(value: false | number): Template<Type, Data> {
364+
return new TemplateClass<Type, Data>(
365365
this.type,
366366
{ raw: [this.raw] },
367367
[],
368368
undefined,
369369
{
370370
indent: value,
371371
},
372-
) as Template<T>;
372+
) as Template<Type, Data>;
373373
}
374-
noindent(): Template<T> {
374+
noindent(): Template<Type, Data> {
375375
return this.indent(false);
376376
}
377-
throw(): Template<T> | never {
377+
throw(): Template<Type, Data> | never {
378378
if (this.error) {
379379
throw this.error;
380380
}
381-
return this as unknown as Template<T>;
381+
return this as unknown as Template<Type, Data>;
382382
}
383-
parse<TParsed = T>(
384-
parser?: (text: string) => TParsed,
385-
): Template<TParsed> {
383+
parse<ParsedData = Data>(
384+
parser?: (text: string) => ParsedData,
385+
): Template<Type, ParsedData> {
386386
this.parser = parser ?? this.parser;
387387
try {
388-
this.data = this.parser?.(this.raw) as T;
388+
this.data = this.parser?.(this.raw) as Data;
389389
} catch (error) {
390390
this.error = error as Error;
391391
}
392-
return this as unknown as Template<TParsed>;
392+
return this as unknown as Template<Type, ParsedData>;
393393
}
394394
}
395395

@@ -406,16 +406,16 @@ export function tag<Type extends string>(
406406
indent: false | number;
407407
},
408408
): Tag<Type> {
409-
return <T>(
409+
return <Data>(
410410
template: { raw: readonly string[] | ArrayLike<string> },
411411
...substitutions: any[]
412-
) => new TemplateClass(type, template, substitutions, parser, options) as Template<T>;
412+
) => new TemplateClass(type, template, substitutions, parser, options) as Template<Type, Data>;
413413
}
414414

415-
type Tag<Type extends string> = <T>(
415+
export type Tag<Type extends string> = <Data>(
416416
template: { raw: readonly string[] | ArrayLike<string> },
417417
...substitutions: any[]
418-
) => Template<T>;
418+
) => Template<Type, Data>;
419419

420420
// Export all template functions individually
421421
// Web languages

0 commit comments

Comments
 (0)