がtypescriptで動作するのに問題があります。 @types/sinon-stub-promise
の定義ファイルには、デフォルトのエクスポートがありません。私は密接にdocs on declaration mergingを追跡しましたが、コンパイルはしません。sinonsの入力を拡張できません
コンパイルエラー:
index.ts(4,18): error TS2345: Argument of type 'typeof 'sinon'' is not assignable to parameter of type 'SinonSandbox'.
Property 'clock' is missing in type 'typeof 'sinon''.
index.ts(6,25): error TS2339: Property 'stub' does not exist on type 'typeof 'sinon''.
Sinonの定義ファイル:
// Generated by typings
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/sinon-stub-promise/sinon-stub-promise.d.ts
/// <reference path="../../../node_modules/@types/sinon/index.d.ts" />
declare module 'sinon' {
interface SinonPromise {
resolves(value?: any): void;
rejects(value?: any): void;
}
interface SinonStub {
returnsPromise(): SinonPromise;
}
}
// Added by me, because this is missing in the typings on dt
declare module 'sinon-stub-promise' {
function setup(sinon: Sinon.SinonSandbox): void;
export = setup;
}
index.ts
import * as sinon from 'sinon';
import sinonStubPromise = require('sinon-stub-promise');
sinonStubPromise(sinon);
:
declare namespace Sinon {
// ...
interface SinonStubStatic {
(): SinonStub;
(obj: any): SinonStub;
(obj: any, method: string): SinonStub;
(obj: any, method: string, func: any): SinonStub;
}
// ...
interface SinonFakeTimers {
now: number;
create(now: number): SinonFakeTimers;
setTimeout(callback: (...args: any[]) => void, timeout: number, ...args: any[]): number;
// ...
}
interface SinonSandbox {
clock: SinonFakeTimers;
// ...
stub: SinonStubStatic;
// ...
}
}
sinon-stub-promiseタイピングを調整
最小限のサンプルレポ:https://github.com/marvinhagemeister/typings-bug
感謝を。残念ながら、私はまだ同じエラーが表示されます: 'index.ts(6,35):error TS2307: 'sinon-stub-promise'モジュールを見つけることができません。 ' – marvinhagemeister
エラーなしでコンパイルする例のレポです。https://github.com/架空の/入力 - バグ – artem
恐ろしい、 '* .d.ts'ファイルを直接インポートできることを知らなかった! – marvinhagemeister