Skip to content

Commit

Permalink
Fix up test to be more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Jun 26, 2024
1 parent 035f66c commit ee9d00b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
types/expect-error-range/expect-error-range-tests.ts
7:7 error [email protected] compile error:
7:7 error [email protected] 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 [email protected] 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: [email protected] compile error:
!!! : Type 'string | undefined' is not assignable to type 'string'.
!!! : Type 'undefined' is not assignable to type 'string'.

test?.trim();
~~~~
!!! @definitelytyped/expect: [email protected], 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: [email protected] 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;
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit ee9d00b

Please sign in to comment.