Skip to content

How to handle global type definition clashes #17663

@Hotell

Description

@Hotell

TypeScript Version: 2.4.2

Let's say I'm using some unit/e2e libraries which are exposing same global functions, for instance test / describe but they have:

  • 1st use case -> structurally similar types for both functions
  • 2nd use case ( contrived one ) -> they have not structurally compatible definitions

-> I wanna got tsc run without errors for whole project ( source / unit tests / e2e files )

use case 1

let's say the test function has signature like this

libraryA:
type Test = (name: string, fn?: ProvidesCallback, timeout?: number) => void;

libraryB:
type Test = (name: string, fn: (t: TestController) => Promise<any>): this;

they have some discrepancies in other defintions but "skipLibCheck": true, comes here to save the day, which is not entirely ok. Why? well now, when I write test(...) I get test definition from libraryA instead of libraryB, which may break when one of those libs changes API, so it's a temporary OKish hack

use case 2

let's say they have different type defs for tests

libraryA:
type Test = (count: number, fn?: ProvidesCallback, timeout: number) => void;

libraryB:
type Test = (name: string, fn: (t: TestController) => Promise<any>): this;

now I'm screwed, because those 2 types are not structurally matching so I won't get tsc running without errors.

only solution for this use case, that comes on my mind, is to create base tsconfig.json, with only global types, that are not clashing and then creating extended tsconfig, which will override types appropriately and run them via -p configOne.json or just via CLI --types

This is currently a issue here:
AlexanderMoskovkin/testcafe-mocha-example#1
DevExpress/testcafe#1537 (comment)

I think either way this should be documented in Typescript docs if there are just solutions that I mentioned.

Thanks for any help !

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions