镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[emitDecoratorMetadata] TypeError: Cannot read property 'kind' of undefined #9135

Closed

Description

The following code crashes the compiler:

// File tmp.ts
class Injectable {

  constructor(...args: any[]) {
    console.log('args:', args);
  }

  static inject(clazz: any, injectables: string[]): void {
    console.log('clazz:', clazz, 'injectables:', injectables);
  }

}


function Inject(args: string[]): Function {
  return (target: any) => {
    Injectable.inject(target, args);
  };
}



@Inject(['a', 'b'])
class A extends Injectable {

  constructor(...injectables) {
    super(...injectables);
  }

}

// Without the decorator
// Injectable.inject(A, ['a', 'b']);

export default A;

Results:

jmlopez in ~/testing$ tsc -v
Version 1.8.10
jmlopez in ~/testing$ tsc tmp.ts --experimentalDecorators --emitDecoratorMetadata
/Users/jmlopez/testing/node_modules/typescript/lib/tsc.js:33078
                throw e;
                ^

TypeError: Cannot read property 'kind' of undefined
    at emitSerializedParameterTypesOfNode (/Users/jmlopez/testing/node_modules/typescript/lib/tsc.js:30799:54)
    at emitSerializedTypeMetadata (/Users/jmlopez/testing/node_modules/typescript/lib/tsc.js:30844:25)
    at emitDecoratorsOfConstructor (/Users/jmlopez/testing/node_modules/typescript/lib/tsc.js:30537:17)
    at emitDecoratorsOfClass (/Users/jmlopez/testing/node_modules/typescript/lib/tsc.js:30514:17)
    at emitClassLikeDeclarationBelowES6 (/Users/jmlopez/testing/node_modules/typescript/lib/tsc.js:30474:17)
    at emitClassLikeDeclaration (/Users/jmlopez/testing/node_modules/typescript/lib/tsc.js:30323:21)
    at emitClassDeclaration (/Users/jmlopez/testing/node_modules/typescript/lib/tsc.js:30319:24)
    at emitJavaScriptWorker (/Users/jmlopez/testing/node_modules/typescript/lib/tsc.js:32383:32)
    at emitNodeWithoutSourceMap (/Users/jmlopez/testing/node_modules/typescript/lib/tsc.js:32189:21)
    at emitNodeWithSourceMap (/Users/jmlopez/testing/node_modules/typescript/lib/tsc.js:32183:21)

It works fine without the --emitDecoratorMetadata. I have also tested in Version 1.9.0-dev.20160217 and I obtain the same error.

Activity

  1. mhegazy commented on Jun 13, 2016

    @mhegazy
    Contributor

    Andy (Andrewkraft) (@Andy-MS) can you take a look.

  2. jmlopez-rod commented on Jun 13, 2016

    @jmlopez-rod
    Author

    Here is a more compact example that makes the compiler crash

    function inject(clazz: any, injectables: (string | any)[]): void {
      console.log('here...');
    }
    
    
    function Inject(args: string[]): Function {
      return (target: any) => {
        inject(target, args);
      };
    }
    
    
    @Inject(['a', 'b'])
    class A {
    
      constructor(...args) {
        inject(this, args);
      }
    
    }
    
    export default A;

    Again, this happens only when using the --emitDecoratorMetadata flag. Another way to fix this is to add the type to args, that is, if we declare the class like this:

    @Inject(['a', 'b'])
    class A {
    
      constructor(...args: any[]) {
        inject(this, args);
      }
    
    }
  3. ghost closed this as completedin #9144on Jun 14, 2016
  4. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions