DevExpress / testcafe

A Node.js tool to automate end-to-end web testing.
https://testcafe.io
MIT License
9.81k stars 667 forks source link

Type-Def: declare Metadata as interface #8231

Closed htho closed 1 month ago

htho commented 1 month ago

What is your Scenario?

I want type safety when I use metadata. Therefore I want to declare the shape of the Metadata type.

What are you suggesting?

This would be possible if Metadata was not defined as a type but as an interface in ./ts-defs-src/test-api/test-info.d.ts.

This way I can create a file like this and declare the expected/known Metadata.

// testcafe.global.d.ts
declare module "testcafe" {
    global {
        interface Metadata {
            manual?: boolean,
        }
    }
}

What alternatives have you considered?

No response

Additional context

This is what ./ts-defs-src/test-api/test-info.d.ts should look like.

// Test Info
//----------------------------------------------------------------------------------------------------------------------

interface Metadata {
    [key: string]: unknown;
}

interface TestInfo {
    name: string;
    meta: Metadata;
}

interface FixtureInfo {
    name: string;
    meta: Metadata;
    path: string;
}
Bayheck commented 1 month ago

Hello,

Could you please try using the following example - it shows how to type check Metadata?

https://github.com/DevExpress/testcafe-examples/tree/master/examples/type-check-for-meta

I look forward to your results.

htho commented 1 month ago

Hi,

no, this does not help, because it does not show errors when wrong metadata is set (except if the generic overload is enforced - test.meta<MetaOptions>).

But only overloading TestFn is not enough, because I want typesafety for all places where Metadata is used: FixtureFn, TestInfo, FixtureInfo, FilterFunction, FilterDescriptor

github-actions[bot] commented 1 month ago

We appreciate you taking the time to share information about this issue. We reproduced the bug and added this ticket to our internal task queue. We'll update this thread once we have news.