-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
area: documentationImprovements or additions to docs 📝Improvements or additions to docs 📝status: accepting prsPlease, send a pull request to resolve this! 🙏Please, send a pull request to resolve this! 🙏
Description
🐛 Bug Report
eslint-plugin-expect-typeversion: 0.2.2- ESLint version: 8.36.0
- Node version: 16.3.0
Actual Behavior
Full reduced test case here: https://github.com/OliverJAsh/eslint-plugin-expect-type-issue
Contents inlined below.
package.json:
{
"dependencies": {
"@typescript-eslint/parser": "^5.55.0",
"eslint": "^8.36.0",
"eslint-plugin-expect-type": "^0.2.2",
"typescript": "^5.0.2"
}
}
tsconfig.json:
{
"compilerOptions": {
"strict": true
}
}
.eslintrc.js:
const path = require("path");
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
project: path.join(__dirname, "./tsconfig.json"),
},
plugins: ["eslint-plugin-expect-type"],
rules: {
"expect-type/expect": "error",
},
};source.ts:
export type Compact<A> = A extends Function ? A : { [K in keyof A]: A[K] } & {};test.ts:
import { Compact } from "./source";
declare const any: any;
const x: Compact<Record<"a" | "b", number> | Record<"a" | "c", number>> = any;
// ❌ Error:
// Expected type to be: { a: number; b: number; } | { a: number; c: number; }, got: Compact<Record<"a" | "b", number> | Record<"a" | "c", number>>
// $ExpectType { a: number; b: number; } | { a: number; c: number; }
type Test1 = typeof x;
// ✅ No error
type Test2 = typeof x;
// ^? type Test2 = {
// a: number;
// b: number;
// } | {
// a: number;
// c: number;
// }$ExpectTypeexpects:Compact<Record<"a" | "b", number> | Record<"a" | "c", number>>- Twoslash expects:
type Test2 = { a: number; b: number; } | { a: number; c: number; }
I believe the reason for this difference is because Twoslash and $ExpectType use different mechanisms to generate the "actual" value:
- Twoslash:
languageService.getQuickInfoAtPosition $ExpectType:checker.typeToString
This particular issue started after we upgraded to TypeScript 5. Prior to this, $ExpectType had the same behavior as Twoslash in this particular example. I'm not sure why this has changed.
Expected Behavior
Twoslash queries and $ExpectType should behave the same.
Reproduction
https://github.com/OliverJAsh/eslint-plugin-expect-type-issue
Metadata
Metadata
Assignees
Labels
area: documentationImprovements or additions to docs 📝Improvements or additions to docs 📝status: accepting prsPlease, send a pull request to resolve this! 🙏Please, send a pull request to resolve this! 🙏