【发布时间】:2018-07-05 13:00:13
【问题描述】:
我明白了 返回类型不相关
重载签名与函数定义不兼容:返回 类型不相关
ReSharper 插件在此错误
public getCache<T>(key: string): T;
public getCache<T>(key: string, defaultValue: T): T;
public getCache<T>(key: string, defaultValue?: T): T
{
const result = localStorage.getItem(key);
return result ? JSON.parse(result) as T : defaultValue;
}
TypeScript 代码。
我明白为什么了。第一次重载中的泛型参数 T 与第二次重载中的 T 没有任何共同之处。我可以写
public getCache<T1>(key: string): T1;
public getCache<T2>(key: string, defaultValue: T2): T2;
public getCache<T>(key: string, defaultValue?: T): T
{
const result = localStorage.getItem(key);
return result ? JSON.parse(result) as T : defaultValue;
}
这个问题有解决办法吗?
我的 ReSharper 版本是 2017.3 (15.5.27130.2024)
【问题讨论】:
标签: typescript resharper