有没有一种解决方案,可以让你做以下操作?
那么,如果你这样做了:
所以
更新:
明确一下,我想要实现的是
my-template.mustache
Hello {{name}}!
index.ts
import { readFileSync, writeFileSync } from 'fs';
import * as Mustache from 'mustache';
export interface Person {
name: string;
}
const hash: Person = {
name: 'Jon'
};
const template = readFileSync('my-template.mustache', 'utf-8');
// somehow let the IDE know the hash type
const result = Mustache.render(template, hash);
writeFileSync('my-template.html', result, 'utf-8');
那么,如果你这样做了:
my-template.mustache
Hello {{name}}, {{age}} <!-- red squiggles under age -->
所以
age
不是Person类型的属性,哈希类型是Person,因此在age
下面会出现红色波浪线。最好使用Visual Studio Code中可用的机制。更新:
明确一下,我想要实现的是
Hello {{name}}, {{age}}<!-- age下面有红色波浪线 -->
,而不是我遇到的问题。