Javascript 财产';formatToParts';不存在于类型';日期时间格式';
我使用的是angular 9,tsconfig设置为es6Javascript 财产';formatToParts';不存在于类型';日期时间格式';,javascript,typescript,Javascript,Typescript,我使用的是angular 9,tsconfig设置为es6 "target": "es6", "lib": [ "es6", "dom" ] 我正在努力做到以下几点: static formatForDisplay(date: Date): string { const dtf = new Intl.DateTimeFormat('en', { year: 'numeric', month: 'short', day: '
"target": "es6",
"lib": [
"es6",
"dom"
]
我正在努力做到以下几点:
static formatForDisplay(date: Date): string {
const dtf = new Intl.DateTimeFormat('en', { year: 'numeric', month: 'short', day: '2-digit' });
const [{ value: mo }, , { value: da }, , { value: ye }] = dtf.formatToParts(date);
return `${mo} ${da}, ${ye}`;
}
但是typescript抱怨我编译的时候(但不是在可视化代码中)
类型“DateTimeFormat”上不存在属性“formatToParts”
为什么会这样?它确实存在将'DateTimeFormat'类型添加到dtf中,如const dtf:DateTimeFormat=..?根据此问题,它似乎已修复,也许您需要检查TS版本?同样,你也可以像这个dtf['formatToParts'](日期)一样使用它作为一个快速的解决方法。我将检查githubadd'DateTimeFormat'类型到dtf,比如const dtf:DateTimeFormat=....?根据这个问题,它似乎已被修复,也许您需要检查您的TS版本?同样,你也可以像这个dtf['formatToParts'](日期)一样使用它作为一个快速的解决方法。我将检查github