Skip to content

TypeScript doesn't compile #558

@alecgibson

Description

@alecgibson

It looks like type definitions were completely reworked in v15.3.0.

For a barebones install repro, this has broken TypeScript compilation (see below).

There are 2 issues:

  1. FakeTimerInstallOpts was renamed to Config, breaking the @types/sinon import. I've already raised a PR against DefinitelyTyped to fix this downstream: [sinon] Fix @sinonjs/fake-timers config import DefinitelyTyped/DefinitelyTyped#74827
  2. It looks like withGlobal has a duplicate declaration from the automated type generation. I can't pretend to know enough about how types are generated in this library to raise a fix. See below for the compilation errors. This is the problematic part of the type definition:
    declare function withGlobal(_global: any): FakeTimers;
    export declare var timers: Timers;
    export declare var createClock: CreateClockCallback;
    export declare var install: InstallCallback;
    export declare var withGlobal: typeof withGlobal;
❯ npm run build

> vite-typescript-starter@0.0.0 build
> tsc

node_modules/@sinonjs/fake-timers/types/fake-timers-src.d.ts:558:18 - error TS2300: Duplicate identifier 'withGlobal'.

558 declare function withGlobal(_global: any): FakeTimers;
                     ~~~~~~~~~~

node_modules/@sinonjs/fake-timers/types/fake-timers-src.d.ts:558:18 - error TS2395: Individual declarations in merged declaration 'withGlobal' must be all exported or all local.

558 declare function withGlobal(_global: any): FakeTimers;
                     ~~~~~~~~~~

node_modules/@sinonjs/fake-timers/types/fake-timers-src.d.ts:562:20 - error TS2300: Duplicate identifier 'withGlobal'.

562 export declare var withGlobal: typeof withGlobal;
                       ~~~~~~~~~~

node_modules/@sinonjs/fake-timers/types/fake-timers-src.d.ts:562:20 - error TS2395: Individual declarations in merged declaration 'withGlobal' must be all exported or all local.

562 export declare var withGlobal: typeof withGlobal;
                       ~~~~~~~~~~

node_modules/@sinonjs/fake-timers/types/fake-timers-src.d.ts:562:20 - error TS2502: 'withGlobal' is referenced directly or indirectly in its own type annotation.

562 export declare var withGlobal: typeof withGlobal;
                       ~~~~~~~~~~

node_modules/@types/sinon/index.d.ts:1185:53 - error TS2694: Namespace '"/home/projects/vitejs-vite-c63jwkxe/node_modules/@sinonjs/fake-timers/types/fake-timers-src"' has no exported member 'FakeTimerInstallOpts'.

1185         useFakeTimers: boolean | Partial<FakeTimers.FakeTimerInstallOpts>;
                                                         ~~~~~~~~~~~~~~~~~~~~

node_modules/@types/sinon/index.d.ts:1335:67 - error TS2694: Namespace '"/home/projects/vitejs-vite-c63jwkxe/node_modules/@sinonjs/fake-timers/types/fake-timers-src"' has no exported member 'FakeTimerInstallOpts'.

1335         useFakeTimers(config?: number | Date | Partial<FakeTimers.FakeTimerInstallOpts>): SinonFakeTimers;
                                                                       ~~~~~~~~~~~~~~~~~~~~


Found 7 errors in 2 files.

Errors  Files
     5  node_modules/@sinonjs/fake-timers/types/fake-timers-src.d.ts:558
     2  node_modules/@types/sinon/index.d.ts:1185

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions