diff --git a/packages/eslint-plugin/test/__file_snapshots__/types/expect-error-range/expect-error-range-tests.ts.lint b/packages/eslint-plugin/test/__file_snapshots__/types/expect-error-range/expect-error-range-tests.ts.lint index a90e0d7ec7..7b46e020f2 100644 --- a/packages/eslint-plugin/test/__file_snapshots__/types/expect-error-range/expect-error-range-tests.ts.lint +++ b/packages/eslint-plugin/test/__file_snapshots__/types/expect-error-range/expect-error-range-tests.ts.lint @@ -1,39 +1,37 @@ types/expect-error-range/expect-error-range-tests.ts - 7:7 error TypeScript@5.4 compile error: + 7:7 error TypeScript@5.4 compile error: Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string' @definitelytyped/expect - 9:7 error TypeScript@5.4, 5.5 compile error: -Property 'trim' does not exist on type 'never' @definitelytyped/expect + 10:7 error TypeScript@5.5 compile error: +Type 'string' is not assignable to type 'never' @definitelytyped/expect ✖ 2 problems (2 errors, 0 warnings) ==== types/expect-error-range/expect-error-range-tests.ts ==== + // In TypeScript <5.5, elem will have type "string", + // but 5.5 it will be "string | number". const elem = ["value", undefined].filter(x => x != null)[0]; - declare const test: typeof elem & undefined - // These should give expect errors: - - const isStringNoIgnore: string = elem; - ~~~~~~~~~~~~~~~~ + // This should error in 5.4, but not 5.5. + const test1a: string = elem; + ~~~~~~ !!! @definitelytyped/expect: TypeScript@5.4 compile error: !!! : Type 'string | undefined' is not assignable to type 'string'. !!! : Type 'undefined' is not assignable to type 'string'. - test?.trim(); - ~~~~ -!!! @definitelytyped/expect: TypeScript@5.4, 5.5 compile error: -!!! : Property 'trim' does not exist on type 'never'. - + // This should error in 5.5, but not 5.4. + const test1b: undefined extends typeof elem ? typeof elem : never = elem; + ~~~~~~ +!!! @definitelytyped/expect: TypeScript@5.5 compile error: +!!! : Type 'string' is not assignable to type 'never'. - // These should give expect these should not: - + // None of these expects should error. // @ts-expect-error <5.5 - const isStringIgnore: string = elem; - + const test2a: string = elem; // @ts-expect-error >=5.5 - test?.trim(); + const test2b: undefined extends typeof elem ? typeof elem : never = elem; diff --git a/packages/eslint-plugin/test/fixtures/types/expect-error-range/expect-error-range-tests.ts b/packages/eslint-plugin/test/fixtures/types/expect-error-range/expect-error-range-tests.ts index 2e51b9fe82..8fb821bbe7 100644 --- a/packages/eslint-plugin/test/fixtures/types/expect-error-range/expect-error-range-tests.ts +++ b/packages/eslint-plugin/test/fixtures/types/expect-error-range/expect-error-range-tests.ts @@ -1,21 +1,19 @@ +// In TypeScript <5.5, elem will have type "string", +// but 5.5 it will be "string | number". const elem = ["value", undefined].filter(x => x != null)[0]; -declare const test: typeof elem & undefined -// These should give expect errors: +// This should error in 5.4, but not 5.5. +const test1a: string = elem; -const isStringNoIgnore: string = elem; +// This should error in 5.5, but not 5.4. +const test1b: undefined extends typeof elem ? typeof elem : never = elem; -test?.trim(); - - - -// These should give expect these should not: +// None of these expects should error. // @ts-expect-error <5.5 -const isStringIgnore: string = elem; - +const test2a: string = elem; // @ts-expect-error >=5.5 -test?.trim(); +const test2b: undefined extends typeof elem ? typeof elem : never = elem;