Skip to content

Commit 8c4825d

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

5 files changed

Lines changed: 22 additions & 22 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/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
"exports": {
2121
".": "./mod.ts"
2222
},
23-
"version": "0.6.0"
23+
"version": "0.6.1"
2424
}

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

src/gen/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
"bin": {
3030
"tmpl-gen": "./runner.ts"
3131
},
32-
"version": "0.6.0"
32+
"version": "0.6.1"
3333
}

vscode-extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "TypeScript Template Engine",
44
"description": "Use TypeScript as a template engine with syntax highlighting for template tag functions",
55
"publisher": "90dy",
6-
"version": "0.6.0",
6+
"version": "0.6.1",
77
"icon": "icon.png",
88
"engines": {
99
"vscode": "^1.60.0"

0 commit comments

Comments
 (0)