mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 06:50:47 -07:00
chore: fix types
This commit is contained in:
+2
-2
@@ -71,10 +71,10 @@ export class Liquid {
|
|||||||
return this.parser.parseFile(file, sync, LookupType.Layouts, currentFile)
|
return this.parser.parseFile(file, sync, LookupType.Layouts, currentFile)
|
||||||
}
|
}
|
||||||
public async parseFile (file: string): Promise<Template[]> {
|
public async parseFile (file: string): Promise<Template[]> {
|
||||||
return toPromise(this.parser.parseFile(file, false))
|
return toPromise<Template[]>(this.parser.parseFile(file, false))
|
||||||
}
|
}
|
||||||
public parseFileSync (file: string): Template[] {
|
public parseFileSync (file: string): Template[] {
|
||||||
return toValue(this.parser.parseFile(file, true))
|
return toValue<Template[]>(this.parser.parseFile(file, true))
|
||||||
}
|
}
|
||||||
public async renderFile (file: string, ctx?: object) {
|
public async renderFile (file: string, ctx?: object) {
|
||||||
const templates = await this.parseFile(file)
|
const templates = await this.parseFile(file)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { FS } from '../fs/fs'
|
|||||||
import { toThenable, Thenable } from '../util/async'
|
import { toThenable, Thenable } from '../util/async'
|
||||||
|
|
||||||
export default class Parser {
|
export default class Parser {
|
||||||
public parseFile: (file: string, sync?: boolean, type?: LookupType, currentFile?: string) => Iterator<Template[]>
|
public parseFile: (file: string, sync?: boolean, type?: LookupType, currentFile?: string) => IterableIterator<any>
|
||||||
|
|
||||||
private liquid: Liquid
|
private liquid: Liquid
|
||||||
private fs: FS
|
private fs: FS
|
||||||
|
|||||||
+3
-3
@@ -37,7 +37,7 @@ function isAsyncIterator (val: any): val is IterableIterator<any> {
|
|||||||
type Task<T> = Thenable<T>
|
type Task<T> = Thenable<T>
|
||||||
|
|
||||||
// convert an async iterator to a thenable (Promise compatible)
|
// convert an async iterator to a thenable (Promise compatible)
|
||||||
export function toThenable<T> (val: IterableIterator<T> | Thenable<T> | any): Thenable<T> {
|
export function toThenable<T> (val: IterableIterator<any> | Thenable<T> | any): Thenable<T> {
|
||||||
if (isThenable(val)) return val
|
if (isThenable(val)) return val
|
||||||
if (isAsyncIterator(val)) return reduce()
|
if (isAsyncIterator(val)) return reduce()
|
||||||
return createResolvedThenable(val)
|
return createResolvedThenable(val)
|
||||||
@@ -64,12 +64,12 @@ export function toThenable<T> (val: IterableIterator<T> | Thenable<T> | any): Th
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toPromise<T> (val: IterableIterator<T> | Thenable<T> | T): Promise<T> {
|
export function toPromise<T> (val: IterableIterator<any> | Thenable<T> | T): Promise<T> {
|
||||||
return Promise.resolve(toThenable(val))
|
return Promise.resolve(toThenable(val))
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the value of async iterator in synchronous manner
|
// get the value of async iterator in synchronous manner
|
||||||
export function toValue<T> (val: IterableIterator<T> | Thenable<T> | T): T {
|
export function toValue<T> (val: IterableIterator<any> | Thenable<T> | T): T {
|
||||||
let ret: T
|
let ret: T
|
||||||
toThenable(val)
|
toThenable(val)
|
||||||
.then((x: any) => {
|
.then((x: any) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user