@@ -300,7 +300,9 @@ export const LANGUAGES: Record<string, LanguageDefinition> = {
300300 } ,
301301} ;
302302
303- class TemplateDocument < T > extends String {
303+ type Template < T > = string & TemplateClass < T > ;
304+
305+ class TemplateClass < T = unknown > extends String {
304306 public readonly type : string ;
305307 public readonly raw : string ;
306308 public data ?: T ;
@@ -350,36 +352,36 @@ class TemplateDocument<T> extends String {
350352 return this . valueOf ( ) ;
351353 }
352354
353- indent ( value : false | number ) : TemplateDocument < T > {
354- return new TemplateDocument < T > (
355+ indent ( value : false | number ) : Template < T > {
356+ return new TemplateClass < T > (
355357 this . type ,
356358 { raw : [ this . raw ] } ,
357359 [ ] ,
358360 undefined ,
359361 {
360362 indent : value ,
361363 } ,
362- ) ;
364+ ) as Template < T > ;
363365 }
364- noindent ( ) : TemplateDocument < T > {
366+ noindent ( ) : Template < T > {
365367 return this . indent ( false ) ;
366368 }
367- throw ( ) : TemplateDocument < T > {
369+ throw ( ) : Template < T > | never {
368370 if ( this . error ) {
369371 throw this . error ;
370372 }
371- return this ;
373+ return this as unknown as Template < T > ;
372374 }
373375 parse < TParsed = T > (
374376 parser ?: ( text : string ) => TParsed ,
375- ) : TemplateDocument < TParsed > {
377+ ) : Template < TParsed > {
376378 this . parser = parser ?? this . parser ;
377379 try {
378380 this . data = this . parser ?.( this . raw ) as T ;
379381 } catch ( error ) {
380382 this . error = error as Error ;
381383 }
382- return this as unknown as TemplateDocument < TParsed > ;
384+ return this as unknown as Template < TParsed > ;
383385 }
384386}
385387
@@ -396,16 +398,16 @@ export function ext<Type extends string>(
396398 indent : false | number ;
397399 } ,
398400) : Ext < Type > {
399- return (
401+ return < T > (
400402 template : { raw : readonly string [ ] | ArrayLike < string > } ,
401403 ...substitutions : any [ ]
402- ) => new TemplateDocument ( type , template , substitutions , parser , options ) ;
404+ ) => new TemplateClass ( type , template , substitutions , parser , options ) as Template < T > ;
403405}
404406
405407type Ext < Type extends string > = < T > (
406408 template : { raw : readonly string [ ] | ArrayLike < string > } ,
407409 ...substitutions : any [ ]
408- ) => TemplateDocument < T > ;
410+ ) => Template < T > ;
409411
410412// Export all template functions individually
411413// Web languages
0 commit comments