Closed k-yle closed 3 years ago
@armanio123 looks like we're straightforwardly missing a case in reportIncompatibleStack
. This might be difficult to construct a test for but we can write another case for code 2626 there.
I'm hitting this as well with typescript 4.2.2
, in a large project with the following tsconfig.json
:
{
"compilerOptions": {
"baseUrl": "./",
"jsx": "preserve",
"noEmit": true,
"module": "esnext",
"esModuleInterop": true,
"strict": true,
"alwaysStrict": true,
"noImplicitThis": false,
"resolveJsonModule": true,
"moduleResolution": "node",
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"paths": {
"~/*": ["./src/*"],
"test/*": ["./test/*"],
"*": ["./typings/*"]
},
"lib": ["es2015", "es2016", "es2017", "es2018", "esnext", "dom"],
"target": "ES2020"
},
"include": ["src", "typings"],
"exclude": [
"node_modules",
"public",
"lib",
"./src/**/__tests__/*.legacy-unit-test.ts",
"./src/**/__tests__/*-itest.ts"
]
}
$ tsc -p .
/app/node_modules/typescript/lib/tsc.js:88051
throw e;
^
Error: Debug Failure. Unhandled Diagnostic: 2626
at reportIncompatibleStack (/app/node_modules/typescript/lib/tsc.js:49104:45)
at reportRelationError (/app/node_modules/typescript/lib/tsc.js:49145:21)
at reportErrorResults (/app/node_modules/typescript/lib/tsc.js:49338:25)
at isRelatedTo (/app/node_modules/typescript/lib/tsc.js:49299:17)
at typeArgumentsRelatedTo (/app/node_modules/typescript/lib/tsc.js:49573:39)
at relateVariances (/app/node_modules/typescript/lib/tsc.js:50032:34)
at structuredTypeRelatedToWorker (/app/node_modules/typescript/lib/tsc.js:49982:46)
at structuredTypeRelatedTo (/app/node_modules/typescript/lib/tsc.js:49689:30)
at recursiveTypeRelatedTo (/app/node_modules/typescript/lib/tsc.js:49665:53)
at isRelatedTo (/app/node_modules/typescript/lib/tsc.js:49279:34)
@stevehollaar any chance you could share code that reproduces the issue? That would help us out a ton
@stevehollaar any chance you could share code that reproduces the issue? That would help us out a ton
Unfortunately the codebase is proprietary and I wasn't able to isolate a small repro.
I ended up debugging this by adding a console.log line:
console.log({source, sourceType });
in tsc.js
, just prior to this line:
reportIncompatibleError(ts.Diagnostics.Type_at_position_0_in_source_is_not_compatible_with_type_at_position_1_in_target, sourceIndex, i);
That gave me:
{
source: Type {
flags: 524288,
id: 117489,
symbol: undefined,
objectFlags: 1114116,
target: <ref *1> Type {
flags: 524288,
id: 1048,
objectFlags: 12,
symbol: undefined,
members: undefined,
properties: undefined,
callSignatures: undefined,
constructSignatures: undefined,
stringIndexInfo: undefined,
numberIndexInfo: undefined,
typeParameters: [Array],
outerTypeParameters: undefined,
localTypeParameters: [Array],
instantiations: [Map],
target: [Circular *1],
resolvedTypeArguments: [Array],
thisType: [Type],
declaredProperties: [Array],
declaredCallSignatures: [],
declaredConstructSignatures: [],
declaredStringIndexInfo: undefined,
declaredNumberIndexInfo: undefined,
elementFlags: [Array],
minLength: 2,
fixedLength: 2,
hasRestElement: false,
combinedFlags: 1,
readonly: false,
labeledElementDeclarations: undefined,
resolvedBaseTypes: [Array],
baseTypesResolved: true
},
resolvedTypeArguments: [ [Type], [Type] ],
members: Map(36) {
'0' => [Symbol],
'1' => [Symbol],
'length' => [Symbol],
'toString' => [Symbol],
'toLocaleString' => [Symbol],
'pop' => [Symbol],
'push' => [Symbol],
'concat' => [Symbol],
'join' => [Symbol],
'reverse' => [Symbol],
'shift' => [Symbol],
'slice' => [Symbol],
'sort' => [Symbol],
'splice' => [Symbol],
'unshift' => [Symbol],
'indexOf' => [Symbol],
'lastIndexOf' => [Symbol],
'every' => [Symbol],
'some' => [Symbol],
'forEach' => [Symbol],
'map' => [Symbol],
'filter' => [Symbol],
'reduce' => [Symbol],
'reduceRight' => [Symbol],
'find' => [Symbol],
'findIndex' => [Symbol],
'fill' => [Symbol],
'copyWithin' => [Symbol],
'__@iterator' => [Symbol],
'entries' => [Symbol],
'keys' => [Symbol],
'values' => [Symbol],
'__@unscopables' => [Symbol],
'includes' => [Symbol],
'flatMap' => [Symbol],
'flat' => [Symbol]
},
properties: [
[Symbol], [Symbol], [Symbol], [Symbol],
[Symbol], [Symbol], [Symbol], [Symbol],
[Symbol], [Symbol], [Symbol], [Symbol],
[Symbol], [Symbol], [Symbol], [Symbol],
[Symbol], [Symbol], [Symbol], [Symbol],
[Symbol], [Symbol], [Symbol], [Symbol],
[Symbol], [Symbol], [Symbol], [Symbol],
[Symbol], [Symbol], [Symbol], [Symbol],
[Symbol], [Symbol], [Symbol], [Symbol]
],
callSignatures: [],
constructSignatures: [],
stringIndexInfo: undefined,
numberIndexInfo: { type: [Type], isReadonly: false, declaration: [Node] }
},
sourceType: Type {
flags: 524288,
id: 117487,
objectFlags: 16,
symbol: Symbol {
flags: 4096,
escapedName: '__object',
declarations: [Array],
valueDeclaration: [Node],
id: undefined,
mergeId: undefined,
parent: undefined,
members: [Map]
},
members: Map(3) {
'notificationId' => [Symbol],
'getTemplateData' => [Symbol],
'generateStartEndDate' => [Symbol]
},
properties: [ [Symbol], [Symbol], [Symbol] ],
callSignatures: [],
constructSignatures: [],
stringIndexInfo: undefined,
numberIndexInfo: undefined
}
}
just prior to the tsc
error, and from there I was able to find the problematic code via the sourceType.members
.
I think there must have been something funky about the way types were shared across module boundaries (possibly related to a circular reference?), as when I tried to repro in the playground, I could not. My "fix" was to explicitly type some exported objects with a shared interface, instead of leaving the type as implicit. I hope this helps!
I'm getting something very similar, but not exactly the same. It compiles fine with 4.1.5 but fails with the error below in 4.2.2. We are using webpack and I'm logging the ts file name as it's being processed, and unfortunately, it's not always happening on the same file. I don't have an easy repro, this solution is proprietary and also contains thousands of typescript files. At first I thought it was when exporting an enum where the enum's values were strings. I noticed the ones that it was crashing on were strings using a single quote and not a double quote, so I changed it, and it seemed to no longer fail on that file. However, I'm no longer certain that's the issue as it's now failing on a file with a large exported class. This class has no members that are strings, although it does use strings in one method, and those strings have single quotes. It's too much to change every file in the project as a test, but this seems like correlation but not necessarily causation anyway. At this point, we are rolling back to 4.1.5.
Error: Debug Failure. Error: Debug Failure. at Object.getModuleSpecifiers (C:\dev\Workspaces\Git\Project\node_modules\.pnpm\typescript@4.2.2\node_modules\typescript\lib\typescript.js:111579:30) at getSpecifierForModuleSymbol (C:\dev\Workspaces\Git\Project\node_modules\.pnpm\typescript@4.2.2\node_modules\typescript\lib\typescript.js:48852:62) at C:\dev\Workspaces\Git\Project\node_modules\.pnpm\typescript@4.2.2\node_modules\typescript\lib\typescript.js:48710:39 at Array.map (<anonymous>) at getSymbolChain (C:\dev\Workspaces\Git\Project\node_modules\.pnpm\typescript@4.2.2\node_modules\typescript\lib\typescript.js:48708:58) at getSymbolChain (C:\dev\Workspaces\Git\Project\node_modules\.pnpm\typescript@4.2.2\node_modules\typescript\lib\typescript.js:48718:51) at lookupSymbolChainWorker (C:\dev\Workspaces\Git\Project\node_modules\.pnpm\typescript@4.2.2\node_modules\typescript\lib\typescript.js:48692:51) at lookupSymbolChain (C:\dev\Workspaces\Git\Project\node_modules\.pnpm\typescript@4.2.2\node_modules\typescript\lib\typescript.js:48685:24) at symbolToTypeNode (C:\dev\Workspaces\Git\Project\node_modules\.pnpm\typescript@4.2.2\node_modules\typescript\lib\typescript.js:48859:29) at typeReferenceToTypeNode (C:\dev\Workspaces\Git\Project\node_modules\.pnpm\typescript@4.2.2\node_modules\typescript\lib\typescript.js:48272:40)
I had same problem. For me it was that I used string as an enum instead of using the actual enum as value.
@heikkis , We use them all over the place. The language allows it: https://www.typescriptlang.org/docs/handbook/enums.html.
I'm having the same error as @ItWorksOnMyMachine.
And I have a small reproduction repo: https://github.com/flybayer/tsc-broken (boilerplate for a new Blitz app)
git clone git@github.com:flybayer/tsc-broken.git
cd tsc-broken
yarn
yarn tsc
In my case, I had code like this that crashed with a 2626 that was hard to debug:
import { defineMessages } from 'react-intl';
type UserSource = 'google' | 'slack' | 'microsoft'
type SourceInfo = {
key: string;
icon: ReactNode;
label: { id: string; defaultMessage: string; description: string };
};
const messages = defineMessages({
slackProvider: {
id: 'fabric.elements.user-picker.slack.provider',
defaultMessage: 'Slack',
description: 'This external user is sourced from Slack provider',
},
});
// @ts-ignore
const SourcesInfoMap = new Map<UserSource, SourceInfo>([
["slack", { key: "slack", icon: <SlackIcon />, label: messages.slackProvider }]
]);
The code doesn't run but I hope it gives you enough idea to tell what the issue is about.
The weird thing is that it crashed even with that // @ts-ignore
in place. The fix was to change the declaration to <UserSource, any>
instead of <UserSource, SourceInfo>
although I know that's not particularly nice.
It's possible there was some issue in the original code that was uncovered by the update to TypeScript 4.2.
I ran across this with svelte-check, and I can share my code. This commit: https://github.com/rpavlik/openxr-changelog-maker/commit/7711de456285ef2f84c101fdd2337a5a865da97d
produces this:
❯ npm run check
> svelte-app@1.0.0 check
> svelte-check
Loading svelte-check in workspace: e:\src-ssd\openxr-changelog-maker
Getting Svelte diagnostics...
====================================
Error: Debug Failure. Unhandled Diagnostic: 2626
at reportIncompatibleStack (E:\src-ssd\openxr-changelog-maker\node_modules\typescript\lib\typescript.js:59271:45)
at reportRelationError (E:\src-ssd\openxr-changelog-maker\node_modules\typescript\lib\typescript.js:59314:21)
at reportErrorResults (E:\src-ssd\openxr-changelog-maker\node_modules\typescript\lib\typescript.js:59580:25)
at isRelatedTo (E:\src-ssd\openxr-changelog-maker\node_modules\typescript\lib\typescript.js:59539:17)
at typeArgumentsRelatedTo (E:\src-ssd\openxr-changelog-maker\node_modules\typescript\lib\typescript.js:59842:39)
at relateVariances (E:\src-ssd\openxr-changelog-maker\node_modules\typescript\lib\typescript.js:60394:34)
at structuredTypeRelatedToWorker (E:\src-ssd\openxr-changelog-maker\node_modules\typescript\lib\typescript.js:60330:46)
at structuredTypeRelatedTo (E:\src-ssd\openxr-changelog-maker\node_modules\typescript\lib\typescript.js:59978:30)
at recursiveTypeRelatedTo (E:\src-ssd\openxr-changelog-maker\node_modules\typescript\lib\typescript.js:59950:64)
at isRelatedTo (E:\src-ssd\openxr-changelog-maker\node_modules\typescript\lib\typescript.js:59490:34)
====================================
svelte-check found 0 errors, 0 warnings and 0 hints
Unfortunately I am not good enough at ts to figure out what's actually causing the problem or to narrow it down. Changing my dependency from "typescript": "^4.0.0
" to "typescript": "~4.1.0"
"fixed" it in that I got a more helpful error message:
❯ npm run check
> svelte-app@1.0.0 check
> svelte-check
Loading svelte-check in workspace: e:\src-ssd\openxr-changelog-maker
Getting Svelte diagnostics...
====================================
e:\src-ssd\openxr-changelog-maker\src\Ref.svelte:34:56
Error: No overload matches this call.
Overload 1 of 3, '(iterable: Iterable<readonly [boolean, ComponentAndProps]>): Map<boolean, ComponentAndProps>', gave the following error.
Argument of type '([true, { component: typeof RefEditable__SvelteComponent_; props: { codeChangeOnly: boolean; ref: PartialReference; submittable: boolean; allowSuffix: boolean; }; }] | [...])[]' is not assignable to parameter of type 'Iterable<readonly [boolean, ComponentAndProps]>'.
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
Type 'IteratorResult<[true, { component: typeof RefEditable__SvelteComponent_; props: { codeChangeOnly: boolean; ref: PartialReference; submittable: boolean; allowSuffix: boolean; }; }] | [...], any>' is not assignable to type 'IteratorResult<readonly [boolean, ComponentAndProps], any>'.
Type 'IteratorYieldResult<[true, { component: typeof RefEditable__SvelteComponent_; props: { codeChangeOnly: boolean; ref: PartialReference; submittable: boolean; allowSuffix: boolean; }; }] | [...]>' is not assignable to type 'IteratorResult<readonly [boolean, ComponentAndProps], any>'.
Type 'IteratorYieldResult<[true, { component: typeof RefEditable__SvelteComponent_; props: { codeChangeOnly: boolean; ref: PartialReference; submittable: boolean; allowSuffix: boolean; }; }] | [...]>' is not assignable to type 'IteratorYieldResult<readonly [boolean, ComponentAndProps]>'.
Type '[true, { component: typeof RefEditable__SvelteComponent_; props: { codeChangeOnly: boolean; ref: PartialReference; submittable: boolean; allowSuffix: boolean; }; }] | [...]' is not assignable to type 'readonly [boolean, ComponentAndProps]'.
Type '[true, { component: typeof RefEditable__SvelteComponent_; props: { codeChangeOnly: boolean; ref: PartialReference; submittable: boolean; allowSuffix: boolean; }; }]' is not assignable to type 'readonly [boolean, ComponentAndProps]'.
The types of '1.component' are incompatible between these types.
Type 'typeof RefEditable__SvelteComponent_' is missing the following properties from type 'SvelteComponentDev': $set, $on, $destroy, $$prop_def, and 5 more. (ts)
};
let components = new Map<boolean, ComponentAndProps>([
[
true,
{
component: RefEditable,
props: editorProps,
},
],
[
false,
{
component: RefView,
props: viewerProps,
},
],
]);
e:\src-ssd\openxr-changelog-maker\src\Ref.svelte:53:5
Error: Type 'ComponentAndProps | undefined' is not assignable to type 'ComponentAndProps'.
Type 'undefined' is not assignable to type 'ComponentAndProps'. (ts)
$: {
active = components.get(editing);
}
e:\src-ssd\openxr-changelog-maker\src\Ref.svelte:60:5
Error: Type '{} | { repo: GitHubRepo; refType: GitHubRefType; refNumber: number; suffix?: string | undefined; } | { repo: "gl"; refType: GitLabRefType; refNumber: number; suffix?: string | undefined; }' is not assignable to type 'null'.
Type '{}' is not assignable to type 'null'. (ts)
editing = false;
viewerProps.ref = { ...normalizedRef };
}
====================================
svelte-check found 3 errors, 0 warnings and 0 hints
npm ERR! code 1
npm ERR! path E:\src-ssd\openxr-changelog-maker
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c svelte-check
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ryanp\scoop\persist\nodejs\cache\_logs\2021-03-05T19_45_01_706Z-debug.log
This is still happening to me with 4.2.4. Same error: Error: Debug Failure. Unhandled Diagnostic: 2626
I don't know how to reproduce it - I added a few lines of code to my app which was essentially adding a new icon, something I've done 20-30 times now with no issue. After adding this code, I get this error.
Edit: there was an actual Typescript error that I fixed in my code to resolve this, but the crash was still happening. It involved some logic with looking up/iterating over a Map
if that's at all helpful.
Just stumbled upon this too, looks like it was the same issue @bscaspar had: https://github.com/getsentry/sentry/pull/25744/commits/5b782112ce527872a0db18e2809fe7486d6ea124#diff-d8015cdd3c4c2b662a481d12aae7ff2f2a0bd8d48021a0a369cbd4f06229a2b8L4-R9
Version 4.2.4 same error. Any idea how to debug it?
Version 4.2.4 same error. Any idea how to debug it?
For me there was an actual typescript error which caused the crash, so I had to debug it the old fashioned way - add changes one at a time until the crash identified the problematic code. Of course there doesn't seem to be enough evidence to confirm that TS errors are the only cause so it may be something that would compile completely fine normally. Good luck!
@bscaspar Thank you. Yes it was an error in TS but not sure where exactly. Maybe SWR lib typing. Sad the lib cant produce some kind of error trace.
fyi - I reverted to version "typescript": "4.0.2" (v. old, but was just what was mentioned in Google search results), and it spat our an error trace with line numbers! I can see that it is an issue with assigning types.
Also getting this crash with 4.2.4. The following changes in the PR started generating this crash in our repository. https://github.com/roblox-ts/roblox-ts/runs/2613701799 https://github.com/roblox-ts/roblox-ts/pull/1392
The second commit in the PR has solved the crash. Compiling with version 4.2.0 gave me this error:
src/TSTransformer/nodes/statements/transformStatement.ts:44:29 - error TS2769: No overload matches this call.
Overload 1 of 3, '(iterable: Iterable<readonly [SyntaxKind, StatementTransformer]>): Map<SyntaxKind, StatementTransformer>', gave the following error.
Argument of type '([SyntaxKind.InterfaceDeclaration, () => List<Statement<keyof StatementByKind>>] | [SyntaxKind.TypeAliasDeclaration, () => List<Statement<keyof StatementByKind>>] | ... 25 more ... |
[...])[]' is not assignable to parameter of type 'Iterable<readonly [SyntaxKind, StatementTransformer]>'.
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
Type 'IteratorResult<[SyntaxKind.InterfaceDeclaration, () => List<Statement<keyof StatementByKind>>] | [SyntaxKind.TypeAliasDeclaration, () => List<Statement<keyof StatementByKind>>] | ... 25 more
... | [...], any>' is not assignable to type 'IteratorResult<readonly [SyntaxKind, StatementTransformer], any>'.
Type 'IteratorYieldResult<[SyntaxKind.InterfaceDeclaration, () => List<Statement<keyof StatementByKind>>] | [SyntaxKind.TypeAliasDeclaration, () => List<Statement<keyof StatementByKind>>] | ... 25 more ... | [...]>' is not assignable to type 'IteratorResult<readonly [SyntaxKind, StatementTransformer], any>'.
Type 'IteratorYieldResult<[SyntaxKind.InterfaceDeclaration, () => List<Statement<keyof StatementByKind>>] | [SyntaxKind.TypeAliasDeclaration, () => List<Statement<keyof StatementByKind>>] | ... 25 more ... | [...]>' is not assignable to type 'IteratorYieldResult<readonly [SyntaxKind, StatementTransformer]>'.
Type '[SyntaxKind.InterfaceDeclaration, () => List<Statement<keyof StatementByKind>>] | [SyntaxKind.TypeAliasDeclaration, () => List<Statement<keyof StatementByKind>>] | ... 25 more ... | [...]' is not assignable to type 'readonly [SyntaxKind, StatementTransformer]'.
Type '[SyntaxKind.ForOfStatement, (state: TransformState, node: ForOfStatement) => List<Node<SyntaxKind>>]' is not assignable to type 'readonly [SyntaxKind, StatementTransformer]'.
Type at position 1 in source is not compatible with type at position 1 in target.
Type 'List<Node<SyntaxKind>>' is not assignable to type 'List<Statement<keyof StatementByKind>>'.
Type 'Node<SyntaxKind>' is not assignable to type 'Statement<keyof StatementByKind>'.
Types of property 'kind' are incompatible.
Type 'SyntaxKind' is not assignable to type 'keyof StatementByKind'.
Overload 2 of 3, '(entries?: readonly (readonly [SyntaxKind, StatementTransformer])[] | null | undefined): Map<SyntaxKind, StatementTransformer>', gave the following error.
Type '(state: TransformState, node: ForOfStatement) => List<Node<SyntaxKind>>' is not assignable to type 'StatementTransformer'.
44 const TRANSFORMER_BY_KIND = new Map<ts.SyntaxKind, StatementTransformer>([
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45 // no emit
~~~~~~~~~~~
...
77 [ts.SyntaxKind.WhileStatement, transformWhileStatement],
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78 ]);
I had the same issue, in my case it was because of passing array to Map constructor. Consider this case:
interface UploadProgress {
progress: number;
}
createUpload(file: File, fileId: string): Observable<Map<string, UploadProgress>> {
...
return fileUploader.startUpload(file).pipe(map((progress) => new Map<string, UploadProgress>([[fileId, { progress }]])));
}
here in return statement progress appears to be not a number as I expect, but an object UploadProgress.
As soon as I rewrite Map constructor without passing there an array, it rewards me with readable compiler exception that helps me figure this out.
return fileUploader.startUpload(file).pipe(map((progress) => new Map<string, UploadProgress>([[fileId, progress ]])));
{ progress }
must be progress
I saw similar array assignment to Map constructor in previous comment, that gave me a hint.
Try
const map = new Map(); map.setValue(key, value);
instead of
new Map([[key, value]])
I was on "typescript": "^4.2.4"
and it was throwing this error with no stack trace. I updated my project to use "typescript": "^4.5.5",
and it handled the error properly and started throwing a stack trace which made it easy to find where the error was. In my case I was extending the global type the react navigation v6 export which caused this error.
I ran in the same issue and I also had a wrong definition of a type i.e.
Wrong
export interface MyInterface {
ct: "contenttype1" | "contenttype2" | undefined
}
Correct
export interface MyInterface {
ct?: "contenttype1" | "contenttype2" | undefined
}
The question mark for undefined type definition ?
was missing.
Bug Report
Regression in
v4.2.1-rc
(EDIT: also an issue inv4.2.2
), tsc fails to compile with an errorDebug Failure. Unhandled Diagnostic: 2626
. It worked fine inv4.2.0-beta
🔎 Search Terms
🕗 Version & Regression Information
v4.2.1-beta
andv4.2.2-rc
I was unable to test this on prior versions because ___⏯ Playground Link
Playground link with relevant code💻 Code
tsconfig:
🙁 Actual behaviour
TSC crashes and fails to compile
🙂 Expected behaviour
It should compile, which worked in v4.2 beta