[英]moment.updateLocale formats not assignable to parameter of type 'void' in angular 4 typescript
I'm currently working on an angular 4 application that needs to use a custom moment locale date format (let's say without the year), on this example 'lll'. 我目前正在开发一个角度4应用程序,该应用程序需要在此示例“ lll”上使用自定义的瞬间语言环境日期格式(假设不带年份)。 On a previous angular 1.5 app, I had this configuration : 在以前的angular 1.5应用程序中,我有以下配置:
moment.updateLocale('en', {
parentLocale: 'en',
longDateFormat: {
lll: 'MMM D HH:mm'
}
});
but when I try to make the same in typescript (Angular 4) I get this error : 但是当我尝试在打字稿(Angular 4)中进行相同的操作时,出现此错误:
[ts] Argument of type '{ parentLocale: string; [ts]类型为'{parentLocale:string; longDateFormat: { lll: string; longDateFormat:{lll:字符串; }; }; }' is not assignable to parameter of type 'void | }'不能分配给'void |类型的参数。 LocaleSpecification'. 语言环境规范”。 Type '{ parentLocale: string; 输入'{parentLocale:string; longDateFormat: { lll: string; longDateFormat:{lll:字符串; }; }; }' is not assignable to type 'LocaleSpecification'. }”不能分配给“ LocaleSpecification”类型。 Types of property 'longDateFormat' are incompatible. 属性'longDateFormat'的类型不兼容。 Type '{ lll: string; 输入'{lll:string; }' is not assignable to type 'LongDateFormatSpec'. }”不能分配给“ LongDateFormatSpec”类型。 Property 'LTS' is missing in type '{ lll: string; 类型'{lll:string;中缺少属性'LTS'。 }'. }'。 (property) longDateFormat: { lll: string; (属性)longDateFormat:{lll:string; } }
I'm pretty new into this, so... where should I look to solve this problem ?. 我对此很陌生,所以...我应该在哪里解决这个问题?
For ppl who will look for the answer to this question, You have to pass all longDateFormat there, not only the one u want to change. 对于将要寻找该问题答案的ppl,您必须在其中传递所有longDateFormat,而不仅仅是您要更改的那个。
interface LongDateFormatSpec {
LTS: string;
LT: string;
L: string;
LL: string;
LLL: string;
LLLL: string;
// lets forget for a sec that any upper/lower permutation will also work
lts?: string;
lt?: string;
l?: string;
ll?: string;
lll?: string;
llll?: string;
}
for example: 例如:
moment.updateLocale('en-gb', {
longDateFormat: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
L: 'DD/MM/YYYY',
LL: 'D MMMM YYYY',
LLL: 'MMM D HH:mm', // Changed here
LLLL: 'dddd, D MMMM YYYY HH:mm'
},
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.