Skip to content

Simplify coverage typings #9770

@AriPerkkio

Description

@AriPerkkio

Clear and concise description of the problem

Now that v8 and istanbul providers support same same identical options, there is no need for complex coverage.provider specific typings.

export type CoverageOptions<T extends CoverageProviderName = CoverageProviderName>
= T extends 'istanbul'
? { provider: T } & CoverageIstanbulOptions
: T extends 'v8' ? {
/**
* Provider to use for coverage collection.
*
* @default 'v8'
*/
provider: T
} & CoverageV8Options
: T extends 'custom'
? { provider: T } & CustomProviderOptions
: { provider?: T } & CoverageV8Options

export interface CoverageIstanbulOptions extends BaseCoverageOptions {}
export interface CoverageV8Options extends BaseCoverageOptions {}
export interface CustomProviderOptions
extends Pick<BaseCoverageOptions, FieldsWithDefaultValues | 'changed'> {
/** Name of the module or path to a file to load the custom provider from */
customProviderModule: string
}

It also seems that currently when vitest.config.ts is included in tsconfig.json's include, the coverage.provider becomes required field. Not sure why. It should default to v8 but it doesn't work anymore 🤷‍♂️
Instead of fixing this complex type, let's just simplify the types overall.

Suggested solution

interface CoverageOptions should just be BaseCoverageOptions. If some option is provider specific (currently none), it should be stated in JSDocs.

Alternative

Fix current complex types so that following would not cause type errors when vitest.config.ts is included in tsconfig.json:

import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    coverage: {
      include: ["src/**/*.{ts,tsx}"],
    },
  },
});
        Property 'provider' is missing in type '{ include: string[]; }' but required in type '{ provider: "v8"; }'.ts(2769)

Additional context

No response

Validations

Metadata

Metadata

Assignees

Labels

feat: coverageIssues and PRs related to the coverage featuretypes

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions