简体   繁体   English

moment.updateLocale格式无法分配给angular 4打字稿中的'void'类型的参数

[英]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.

相关问题 如何正确使用两次moment.updateLocale? - How to use moment.updateLocale twice correctly? 获取警告弃用:moment.updateLocale(); 此刻与语言环境 js - Get warning deprecation : moment.updateLocale(); at moment-with-locales js 返回“void”类型参数的打字稿不能分配给“TimerHandler”类型的参数? - Typescript returning Argument of type 'void' is not assignable to parameter of type 'TimerHandler? TypeScript 错误 '(response) =&gt; void' 类型的参数不可分配给'(value: void) =&gt; void | 类型的参数承诺喜欢<void> '</void> - TypeScript error Argument of type '(response) => void' is not assignable to parameter of type '(value: void) => void | PromiseLike<void>' Typescript 类型 boolean 不可分配给 void - Typescript type boolean is not assignable to void 无效类型不能分配给布尔类型(反应/打字稿) - Type Void is Not Assignable to Type Boolean (React/Typescript) 打字稿错误:类型&#39;undefined []&#39;不能分配给&#39;void&#39;类型 - Typescript error: Type 'undefined[]' is not assignable to type 'void' 打字稿:类型&#39;Promise &lt;{}&gt;&#39;不能分配给&#39;Promise&#39; <void> “ - Typescript : Type 'Promise<{}>' is not assignable to type 'Promise<void>' React Typescript不可分配给type参数 - React typescript is not assignable to parameter of type 类型 'void' 不可分配给类型 '((event: ChangeEvent<htmlinputelement> ) =&gt; void) 反应 TypeScript</htmlinputelement> - Type 'void' is not assignable to type '((event: ChangeEvent<HTMLInputElement>) => void) React TypeScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM