我曾经像这样加载一个json文件:
import faq from './faq.json'
interface FAQ {
title: string
body: string
}
interface SiteConfig {
title: string
faqs: FAQ[]
}
sites: {[key: string]: SiteConfig} = {
siteA: {
title: 'xx',
faqs: faq
}
}
现在我想使用动态导入:
interface FAQ {
title: string
body: string
}
interface SiteConfig {
title: string
faqs: () => FAQ[]
}
sites: {[key: string]: SiteConfig} = {
siteA: {
title: 'xx',
faqs: (): Promise<FAQ[]> => import('./faq.json')
}
}
失败:
Type 'Promise<typeof "*.json">' is not assignable to type 'Promise<FAQ[]>'.