3

我想在 TypeScript中使用我自己的全局类型(没有import, using )。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>) => { ... }
4

0 回答 0