Skip to content

Support error codes in ts-expect-error and ts-ignore comments #38288

@jednano

Description

@jednano

Search Terms

ts-expect-error ts-ignore comment specify support error code codes filter

Suggestion

Please consider supporting one or more error codes following a // @ts-expect-error or // @ts-ignore comment.

Use Cases

This makes testing TypeScript code extremely more accurate.

  1. You want to ignore a specific error code or codes, but still fail on unexpected errors.
  2. You expect a specific error code or codes, but you still don't want to compile unexpected errors.

Examples

// @ts-ignore(1, 2, ...)
// @ts-expect-error(1, 2, ...)

// ----------

// Type 'string' is not assignable to type 'number | boolean | null | undefined'.
// @ts-expect-error(2322)
fn<{ a: number }>({ a: 'b' });

// Type 'number' is not assignable to type 'boolean | null | undefined'.
// @ts-expect-error(2322)
fn<{ a: boolean }>({ a: 42 });

// This condition will always return 'false' since the types 'true' and 'false'
// have no overlap.
// @ts-expect-error(2367)
fn<{ a: boolean }>({ a: false }).a === false;

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions