chore: fix types

This commit is contained in:
Harttle
2021-10-16 22:36:46 +08:00
committed by harttle
parent 8894cbfe6e
commit b5b2a98d5e
3 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -71,10 +71,10 @@ export class Liquid {
return this.parser.parseFile(file, sync, LookupType.Layouts, currentFile)
}
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[] {
return toValue(this.parser.parseFile(file, true))
return toValue<Template[]>(this.parser.parseFile(file, true))
}
public async renderFile (file: string, ctx?: object) {
const templates = await this.parseFile(file)
+1 -1
View File
@@ -14,7 +14,7 @@ import { FS } from '../fs/fs'
import { toThenable, Thenable } from '../util/async'
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 fs: FS
+3 -3
View File
@@ -37,7 +37,7 @@ function isAsyncIterator (val: any): val is IterableIterator<any> {
type Task<T> = Thenable<T>
// 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 (isAsyncIterator(val)) return reduce()
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))
}
// 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
toThenable(val)
.then((x: any) => {