TS 7: Property 'not' does not exist on type Assertion<void, T>

Open Beginner friendly
#11,144 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
testing-qa

Research direction

Start at the exported Assertion type declaration and the Vitest assertion typings described in the issue. Reproduce the failure with the three files shown and run pnpm exec tsc --noEmit. The work is done when expect("a").not.toBe("b") typechecks under TypeScript 7.0.2 without affecting the existing runtime API.

Written by the indexing model from the issue text.

Description

p3-minor-bug
Describe the bug

On TypeScript 7.0.2, expect(value).not.toBe(...) fails to typecheck:

error TS2339: Property 'not' does not exist on type 'Assertion<void, string>'.

Runtime is fine. Vitest 5.0.0 documents .not and the Jest/Chai APIs both use it.

Assertion does not declare not. It is supposed to come from the circular mapped type over Chai.Assertion:

type VitestAssertion<A, R extends void | Promise<void>, T = unknown> = {
  [K in keyof A]: A[K] extends Chai.Assertion
    ? Assertion<R, T>
    : /* ... */
} & ((type: string, message?: string) => Assertion<R, T>)

export interface Assertion<R extends void | Promise<void> = void, T = unknown>
  extends VitestAssertion<Chai.Assertion, R, T>,
    JestAssertion<R, T>,
    ChaiMockAssertion<R, T>,
    Matchers<R, T> { /* ... */ }

Under TypeScript 7 that mapping drops .not. Declaring not: Assertion<R, T> on Assertion restores it.

Happy to send a one-line PR if you want that explicit field.

Reproduction

Three files. Then pnpm exec tsc --noEmit.

package.json:

{
  "type": "module",
  "devDependencies": {
    "typescript": "7.0.2",
    "vitest": "5.0.0"
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "strict": true,
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "skipLibCheck": true
  },
  "include": ["repro.ts"]
}

repro.ts:

import { expect } from "vitest"

expect("a").not.toBe("b")

Expected: tsc --noEmit succeeds (same as TypeScript 5 with Vitest 4).

Actual:

repro.ts:3:13 - error TS2339: Property 'not' does not exist on type 'Assertion<void, string>'.
System Info
System:
  OS: macOS (Darwin arm64)
Binaries:
  Node: 24.14.1
  pnpm: 12.3.1
npmPackages:
  typescript: 7.0.2
  vitest: 5.0.0
  vite: 8.2.2
Used Package Manager

pnpm

Validations
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 18h
Merged PRs (30d)
89

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vitest-dev/vitest

All issues in vitest-dev/vitest

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.