Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of undefined (reading 'get') at getTypeAliasInstantiation #53287

Open
Itrulia opened this issue Mar 16, 2023 · 5 comments · May be fixed by #58326
Open

TypeError: Cannot read properties of undefined (reading 'get') at getTypeAliasInstantiation #53287

Itrulia opened this issue Mar 16, 2023 · 5 comments · May be fixed by #58326
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@Itrulia
Copy link

Itrulia commented Mar 16, 2023

Bug Report

🔎 Search Terms

getTypeAliasInstantiation, (reading 'get'), TypeError: Cannot read properties of undefined, createMarkerType

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ~4.6.0 and ~4.7.0 and is still present in 4.9.5

We have only now figured out something went wrong as we used babel to transpile and fork-ts-checker-webpack-plugin to type check. This caused the type checking to silently fail, which has caused a few bugs lately.

⏯ Playground Link

I don't have a Playground Link as I have no clue what causes it. But the repository is public:

https://github.com/wepublish/wepublish/tree/8e4198788c2d60aa5f03869a6fdf9bda2566b45f
The command needed to reproduce it: npm i && npx tsc -p ./apps/editor/tsconfig.app.json

If typescript version is set to ~4.6.0 everything works. If typescript is set to 4.7 or above, it fails

💻 Code

// We can quickly address your report if:
//  - The code sample is short. Nearly all TypeScript bugs can be demonstrated in 20-30 lines of code!
//  - It doesn't use external libraries. These are often issues with the type definitions rather than TypeScript bugs.
//  - The incorrectness of the behavior is readily apparent from reading the sample.
// Reports are slower to investigate if:
//  - We have to pare too much extraneous code.
//  - We have to clone a large repo and validate that the problem isn't elsewhere.
//  - The sample is confusing or doesn't clearly demonstrate what's wrong.

I haven't been able to produce a minimal reproduction.

🙁 Actual behavior

TSC crashes with an error thrown:

❯ npx tsc -p ./apps/editor/tsconfig.app.json
/Users/itrulia/Documents/wepublish/node_modules/typescript/lib/tsc.js:98439
                throw e;
                ^

TypeError: Cannot read properties of undefined (reading 'get')
    at getTypeAliasInstantiation (/Users/itrulia/Documents/wepublish/node_modules/typescript/lib/tsc.js:50531:54)
    at createMarkerType (/Users/itrulia/Documents/wepublish/node_modules/typescript/lib/tsc.js:56512:17)
    at _loop_23 (/Users/itrulia/Documents/wepublish/node_modules/typescript/lib/tsc.js:56477:45)
    at getVariancesWorker (/Users/itrulia/Documents/wepublish/node_modules/typescript/lib/tsc.js:56498:21)
    at getVariances (/Users/itrulia/Documents/wepublish/node_modules/typescript/lib/tsc.js:56455:17)
    at structuredTypeRelatedToWorker (/Users/itrulia/Documents/wepublish/node_modules/typescript/lib/tsc.js:55675:41)
    at structuredTypeRelatedTo (/Users/itrulia/Documents/wepublish/node_modules/typescript/lib/tsc.js:55305:30)
    at recursiveTypeRelatedTo (/Users/itrulia/Documents/wepublish/node_modules/typescript/lib/tsc.js:55274:30)
    at isRelatedTo (/Users/itrulia/Documents/wepublish/node_modules/typescript/lib/tsc.js:54853:25)
    at isRelatedToWorker (/Users/itrulia/Documents/wepublish/node_modules/typescript/lib/tsc.js:54773:24)

🙂 Expected behavior

TypeScript does not crash and returns the relevant errors

Itrulia added a commit to wepublish/wepublish that referenced this issue Mar 16, 2023
…caused the build to silently fail

This caused that Babel transpiled the code but no type checking ever failed, which meant we were basically just writing JavaScript with TypeScript syntax

ref microsoft/TypeScript#53287
Itrulia added a commit to wepublish/wepublish that referenced this issue Mar 16, 2023
…caused the build to silently fail (#878)

This caused that Babel transpiled the code but no type checking ever failed, which meant we were basically just writing JavaScript with TypeScript syntax

ref microsoft/TypeScript#53287
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 17, 2023
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.1.0 milestone Mar 17, 2023
@huw
Copy link

huw commented May 7, 2023

As far as I can tell this is related to #49458 also

@RyanCavanaugh
Copy link
Member

Compiler test

// @strict: true
// @skipLibCheck: false
// @skipDefaultLibCheck: true

// @filename: node_modules/package/source.d.ts
export interface SourceType<A = any> { }

// @filename: node_modules/package/subuser.d.ts
import { UserType } from './user';
import { SourceType } from './index';
export class SubUser extends UserType {
    doSomething(client: SourceType): void;
}

// @filename: node_modules/package/user.d.ts
import { SourceType } from './source';
export type Manipulation<T> = T extends Array<infer U> ? U : never;
export declare class UserType {
    doSomething(client: SourceType<Manipulation<any>>): void;
}

// @filename: node_modules/package/index.d.ts
export { type SourceType } from "./source"
export { type SubUser } from "./subuser"

// @filename: index.ts
import { SourceType } from "package"

declare module "package" {
    type SourceType = string;
}

@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Apr 26, 2024
@imprakharshukla
Copy link

@iisaduan When will this merged? I am having the same issue and I cannot build my app it always fails with:

/backend:build: TypeError: Cannot read properties of undefined (reading 'get')
/backend:build:     at getTypeAliasInstantiation (/Users/xxxx/Code/github/lumoflo/node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/lib/tsc.js:55837:46)

@iisaduan
Copy link
Member

iisaduan commented May 6, 2024

@imprakharshukla , Working on it! If you would like to see if the fix works for you, you can try it: #58326 (comment)

@iisaduan
Copy link
Member

iisaduan commented May 8, 2024

@imprakharshukla If you're hitting this in your codebase, it is likely because there is a symbol merge that shouldn't have previously been allowed in your code. The new version should help point out where the issue is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants