![](/img/trans.png)
[英]Angular2/TypeScript: error TS2345: Argument of type 'String' is not assignable to parameter of type 'string'
[英]Angular 5 error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'
我需要设置如下cookie:
start: number;
...
this.start = Math.floor(Date.now()/1000);
...
if(!this._cookieService.check('confirmTimeoutStarted')){
this._cookieService.set('confirmTimeoutStarted', this.start);
}
但是我得到:
error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
我应该定义Cookie变量类型还是其他?
Cookies以字符串格式存储。 看起来this._cookieService.set
方法的签名接受字符串,因此您可以执行以下操作:
this._cookieService.set('confirmTimeoutStarted', String(this.start));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.