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"],
})
);
})();
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.Versions
tsd
: 0.19.0typescript
: 4.5.4