与TypeScript中的全局类型冲突

时间:2019-05-17 14:50:39

标签: typescript global declare name-collision

我想在TypeScript中使用自己的全局类型(不使用import,使用declare type)。例如:

// File with global types.
declare type Function<TParameter, TResult> = (parameter: TParameter) => TResult

// Another file.
const someMethod = (callback: Function<number, string>) => { ... }

但是,由于TS2300: Duplicate identifier 'Function'.或任何外部库而导致冲突(lib.es5.d.ts)。有什么方法可以忽略现有的Function声明并使用我自己的声明?

我知道的唯一解决方案是将所有自己的类型放入名称空间:

// File with global types
declare type MyTypes.Function<TParameter, TResult> = (parameter: TParameter) => TResult

// Another file.
const someMethod = (callback: MyTypes.Function<number, string>) => { ... }

0 个答案:

没有答案