tsdjs / tsd

Check TypeScript type definitions
MIT License
2.4k stars 67 forks source link

expectError doesn't recognize TypeScript errors that end with "Did you mean ..."? #138

Closed aqrln closed 2 years ago

aqrln commented 2 years ago

Reproduction repo

https://github.com/aqrln/tsd-repro/

Summary

When a string literal doesn't match the expected literal type, but is similar to the expected one, TypeScript now suggests the correct spelling. expectError fails to recognize the error in this case, and reports the "Expected an error, but found none" message alongside the original TypeScript error.

export type UserFieldEnum = "id" | "email" | "name";

export function findMany(args: { distinct: UserFieldEnum[] }): Promise<unknown>;
// Works.
// Original TypeScript error: `Type '"invalidField"' is not assignable to type 'UserFieldEnum'.`
(async () => {
  expectError(
    await findMany({
      distinct: ["id", "invalidField", "name"],
    })
  );
})();

// Fails with:
// index.test-d.ts:15:23
//  ✖  19:2   Expected an error, but found none.
//  ✖  21:23  Type "mail" is not assignable to type UserFieldEnum. Did you mean "email"?
(async () => {
  expectError(
    await findMany({
      distinct: ["id", "mail", "name"],
    })
  );
})();

Versions