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 property 'valueDeclaration' of undefined #46223

Closed
huan opened this issue Oct 5, 2021 · 5 comments · Fixed by #46350
Closed

TypeError: Cannot read property 'valueDeclaration' of undefined #46223

huan opened this issue Oct 5, 2021 · 5 comments · Fixed by #46350
Assignees
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue

Comments

@huan
Copy link

huan commented Oct 5, 2021

Reproduce steps

$ git clone git@github.com:huan/clone-class.git
$ cd clone-class
$ git checkout f87276a443eb5d11e78d0ce21819b89ac16452d1
$ npm install
$ npx tsc --version
Version 4.4.3

$ npx tsc 
/Users/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:92656
                throw e;
                ^

TypeError: Cannot read property 'valueDeclaration' of undefined
    at checkIndexConstraints (/Users/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:66778:47)
    at checkClassLikeDeclaration (/Users/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:67070:17)
    at checkClassDeclaration (/Users/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:66966:13)
    at checkSourceElementWorker (/Users/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:68323:28)
    at checkSourceElement (/Users/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:68165:17)
    at Object.forEach (/Users/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:132:30)
    at checkBlock (/Users/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:65555:20)
    at checkSourceElementWorker (/Users/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:68286:28)
    at checkSourceElement (/Users/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:68165:17)
    at checkFunctionOrMethodDeclaration (/Users/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:65253:13)

Related Issue

@DanielRosenwasser
Copy link
Member

There's a lot of files in this repo; would you be able to help us narrow down the issue more quickly by providing a minimal repro with just 1-2 files?

@andrewbranch
Copy link
Member

Does the issue reproduce with typescript@next?

@andrewbranch andrewbranch added the Needs More Info The issue still hasn't been fully clarified label Oct 6, 2021
@huan
Copy link
Author

huan commented Oct 6, 2021

@DanielRosenwasser I have tried to make this issue reproducible with fewer files, however, I can only point out that this problem is related to the following lines:

type Constructor<I extends Object> = InstanceInterface<I>

/**
 * Huan(202110): TypeError: Cannot read property 'valueDeclaration' of undefined #58
 *  https://github.com/huan/clone-class/issues/58
 */
// type Constructor<I extends Object, C = any> = ClassInterface<C> & InstanceInterface<I>

If I uncomment the bottom line, then this issue will appear.

However, if I only get this file out of the whole repo, then this issue will disappear. It seems it's related to this line, plus some other unknown files.


@andrewbranch Yes, this issue still reproduces with typescript@next version 4.5.0-dev

$ npx tsc --version
Version 4.5.0-dev.20211006

$ npx tsc
/home/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:94207
                throw e;
                ^

TypeError: Cannot read property 'valueDeclaration' of undefined
    at checkIndexConstraints (/home/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:67995:47)
    at checkClassLikeDeclaration (/home/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:68287:17)
    at checkClassDeclaration (/home/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:68183:13)
    at checkSourceElementWorker (/home/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:69606:28)
    at checkSourceElement (/home/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:69444:17)
    at Object.forEach (/home/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:132:30)
    at checkBlock (/home/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:66768:20)
    at checkSourceElementWorker (/home/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:69569:28)
    at checkSourceElement (/home/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:69444:17)
    at checkFunctionOrMethodDeclaration (/home/huan/git/huan/clone-class/node_modules/typescript/lib/tsc.js:66466:13)

@andrewbranch andrewbranch added Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output and removed Needs More Info The issue still hasn't been fully clarified labels Oct 6, 2021
@andrewbranch andrewbranch added this to the TypeScript 4.6.0 milestone Oct 6, 2021
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Oct 6, 2021

Here's the repro

// @noEmit: true

export type ClassInterface<C> = {
    [key in keyof C]: C[key];
}

type InstanceInterface<I> = {
    new(...args: any[]): I
    prototype: I
}

type Constructor<I extends Object, C = any> = ClassInterface<C> & InstanceInterface<I>

function cloneClass<T extends Constructor<{}>>(OriginalClass: T): T {
    class AnotherOriginalClass extends OriginalClass {
        constructor(...args: any[]) {
            super(...args)
        }
    }
    return AnotherOriginalClass
}

@huan
Copy link
Author

huan commented Oct 13, 2021

Dear @DanielRosenwasser , it's so brilliant to get the reproducible code!

Before fixing it, could we have any workaround for this code, so that my repo can work as expected under a specific version of TypeScript(4.4, or next, or dev version are all acceptable)?

Thank you very much and appreciate your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants