在使用angular6,有使用到这个js库:https://github.com/tmaeda1981jp/string-format-js
主要使用其中类似'This is a %s'.format('pen') === 'This is a pen'的方法。
但在引入该js后,直接在ts中对string使用该format方法,会报如下错误:
ERROR in src/app/routes/openstack/overview.component.ts(193,75): error TS2339: Property 'format' does not exist on type '"up{node_type=\"%s\",component=\"node\"}"'
最终在网上查找相关的解决方案:
在typing.d.ts增加如下声明:
interface String{
format:any
}
之后在ts中针对string变量使用format方法就正常了。