Skip to content

@ts-expect-error and @ts-ignore overly broad in supressing errors #47551

Closed
@MLoughry

Description

@MLoughry

Bug Report

We migrated our codebase with >1.5M lines of TS code to use strict mode everywhere, resulting in >30k new errors caught by strict mode. To ease the migration, we annotated each error with // @ts-expect-error and additional comments pointing to a wiki about the migration. However, we're finding the disable comment to be overly-broad, suppressing new errors that are unrelated to the line in question or strict mode. In particular, adding a new property to a type doesn't flag instances where we have a @ts-expect-error suppressing a strictNullChecks error.

🔎 Search Terms

ignore, expect, error, @ts-ignore, @ts-expect-error

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about @ts-ignore and @ts-expect-error

⏯ Playground Link

https://www.typescriptlang.org/play?ts=4.5.4#code/JYOwLgpgTgZghgYwgAgGIHt3IN4ChnJwBcyIArgLYBG0A3PslSQM5hSgDm9AvrrgPT9kAUQAeABwgJIAE2TQo6KMhlkUYLAAMyIGRBigIMzcnGLJUMAE9kmuJoA0AoVTJhkzMuLMRmzX-JQisqq6lgUwH6cpubQ1rZUmrgI6CCsjHBQJBhYALw4DILIAAJgzAC0EBJSYJVBSgzEyDp6BiBGuLzOyADC6BTiwAA20MgpQTVDNgpKzMipyGAAFig0Q+gA7shDhsgAFJopae5UcABe2ZjI+diaAJTdoYtYyygRUSAcMegW8ZqJyVS6VOFzQVxujRIAEZOkA

Playground link with relevant code

💻 Code

interface Foo {
  a: number;
  b: string;
}

// Expected error due to `undefined` property `a`,
// but suppresses error due to missing property `b`
const bar: Foo = {
  // @ts-expect-error
  a: undefined
}

// Compiler correctly errors on the below line (`const baz: Foo = {`)
// due to the missing property `b`
const baz: Foo = {
  a: 1
}

🙁 Actual behavior

Compiler suppresses error about missing property.

🙂 Expected behavior

Compiler raises error about missing property that is not on the line covered by @ts-expect-error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions