ts-node: New TS errors after updating to v6.0.0

Since I updated, I have been getting a lot of new TS errors that I haven’t gotten before. When I run my tests in v5.0.1 they all pass and everything runs fine.

  Default
    ✓ should throw InvalidArgumentException if value does not match property type
    ✓ should attach a DefaultAnnotation to the decorated property
    ✓ should return the specified default value if initial value is null or undefined

  Description
    ✓ should attach a DescriptionAnnotation to the decorated properties

  Entity
    ✓ should attach an EntityAnnotation to the decorated class

  AcceptValidator
    ✓ should throw an InvalidArgumentException if it is not constructed with an array
    ✓ should throw an InvalidArgumentException if it is constructed with an empty array
    ✓ should fail validation if the passed in value is not in the accepted values array
    ✓ should pass validation if the passed in value is in the accepted values array

  Accept
    ✓ should attach an AcceptValidator to the decorated properties metadata

  ElementTypeValidator
    ✓ should should throw an InvalidArgumentException if a function is not passed in to constructor
    ✓ should should throw an InvalidArgumentException if the value to validate is not an Array
    ✓ should fail validation if the type of value does not match the type with which the validator was constructed
    ✓ should fail validation when value is a primitive and does not match the type with which the validator was constructed
    ✓ should pass validation if the type of value does match the type with which the validator was constructed
    ✓ should pass validation when value is a primitive and does match the type with which the validator was constructed

  ElementType
    ✓ should throw an UnsupportedOperationException if the decorated property is not an Array type
    ✓ should attach an ElementTypeValidator to the decorated property's metadata

  RequiredValidator
    ✓ should fail validation if value is null or undefined
    ✓ should pass validation if value is not null and not undefined

  Required
    ✓ should attach a RequiredValidator to the decorated property's metadata

  TypeValidator
    ✓ should should throw an InvalidArgumentException if a function is not passed in to constructor
    ✓ should fail validation if the type of value does not match the type with which the validator was constructed
    ✓ should fail validation when value is a primitive and does not match the type with which the validator was constructed
    ✓ should pass validation if the type of value does match the type with which the validator was constructed
    ✓ should pass validation when value is a primitive of the type with which the validator was constructed
    ✓ should return true if value is null or undefined

  Type
    ✓ should attach a TypeValidator to the decorated property's metadata

  validateEntity
    ✓ should run validators on entity
    ✓ should run validators on any nested entities
    ✓ should throw an error for each validator that fails
    ✓ should throw errors for all nested validators at once

  setClassProperties
    ✓ should throw an InvalidArgumentException if passed null or undefined for the properties argument
    ✓ should throw an InvalidArgumentException if passed null or undefined for the classPrototype argument
    ✓ should assign passed in properties to the passed in class prototype

Here are the results when I run it with v6.0.0

TSError: ⨯ Unable to compile TypeScript
src/metadata/annotation/default-annotation/default-annotation.spec.ts (35,17): Parameter 'exception' implicitly has an 'any' type. (7006)
src/metadata/annotation/default-annotation/default-annotation.spec.ts (59,31): Element implicitly has an 'any' type because type '{}' has no index signature. (7017)
    at getOutput (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:329:15)
    at Object.compile (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:515:11)
    at Module.m._compile (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:402:43)
    at module.exports (/home/john/code/magellan-collections/node_modules/nyc/node_modules/default-require-extensions/js.js:8:9)
    at /home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4
    at require.extensions.(anonymous function) (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:405:12)
    at /home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4
    at require.extensions.(anonymous function) (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:405:12)
    at Object.<anonymous> (/home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at /home/john/code/magellan-collections/node_modules/mocha/lib/mocha.js:253:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/home/john/code/magellan-collections/node_modules/mocha/lib/mocha.js:250:14)
    at Mocha.run (/home/john/code/magellan-collections/node_modules/mocha/lib/mocha.js:577:10)
    at Object.<anonymous> (/home/john/code/magellan-collections/node_modules/mocha/bin/_mocha:591:18)
    at Module._compile (module.js:660:30)
    at Module.replacementCompile (/home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:58:13)
    at module.exports (/home/john/code/magellan-collections/node_modules/nyc/node_modules/default-require-extensions/js.js:8:9)
    at Object.<anonymous> (/home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at runMain (/home/john/.node-spawn-wrap-14751-4772e3a9bdc9/node:68:10)
    at Function.<anonymous> (/home/john/.node-spawn-wrap-14751-4772e3a9bdc9/node:171:5)
    at Object.<anonymous> (/home/john/code/magellan-collections/node_modules/nyc/bin/wrap.js:23:4)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at /home/john/.node-spawn-wrap-14751-4772e3a9bdc9/node:178:8
    at Object.<anonymous> (/home/john/.node-spawn-wrap-14751-4772e3a9bdc9/node:181:3)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at startup (bootstrap_node.js:193:16)
    at bootstrap_node.js:617:3

I did try to fix those specific errors but when I do, I just get more and on things that are definitely typed. In order to just try to get around the implicit any errors, I just disabled that check in my tsconfig.json. That takes care of the implicit any errors, but that just results in one that makes even less sense.

TSError: ⨯ Unable to compile TypeScript
src/exceptions/exception.ts (5,14): Property 'message' does not exist on type 'Exception'. (2339)
src/exceptions/exception.ts (6,14): Property 'name' does not exist on type 'Exception'. (2339)
    at getOutput (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:329:15)
    at Object.compile (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:515:11)
    at Module.m._compile (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:402:43)
    at Module.m._compile (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:402:23)
    at module.exports (/home/john/code/magellan-collections/node_modules/nyc/node_modules/default-require-extensions/js.js:8:9)
    at /home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4
    at require.extensions.(anonymous function) (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:405:12)
    at /home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4
    at require.extensions.(anonymous function) (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:405:12)
    at Object.<anonymous> (/home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/john/code/magellan-collections/src/exceptions/invalid-argument-exception.ts:1:1828)
    at Module._compile (module.js:660:30)
    at Module.replacementCompile (/home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:58:13)
    at Module.m._compile (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:402:23)
    at Module.m._compile (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:402:23)
    at module.exports (/home/john/code/magellan-collections/node_modules/nyc/node_modules/default-require-extensions/js.js:8:9)
    at /home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4
    at require.extensions.(anonymous function) (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:405:12)
    at /home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4
    at require.extensions.(anonymous function) (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:405:12)
    at Object.<anonymous> (/home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/john/code/magellan-collections/src/exceptions/exceptions.index.ts:1:1189)
    at Module._compile (module.js:660:30)
    at Module.replacementCompile (/home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:58:13)
    at Module.m._compile (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:402:23)
    at Module.m._compile (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:402:23)
    at module.exports (/home/john/code/magellan-collections/node_modules/nyc/node_modules/default-require-extensions/js.js:8:9)
    at /home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4
    at require.extensions.(anonymous function) (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:405:12)
    at /home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4
    at require.extensions.(anonymous function) (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:405:12)
    at Object.<anonymous> (/home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/john/code/magellan-collections/src/metadata/annotation/default-annotation/default-annotation.spec.ts:4:1)
    at Module._compile (module.js:660:30)
    at Module.replacementCompile (/home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:58:13)
    at Module.m._compile (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:402:23)
    at Module.m._compile (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:402:23)
    at module.exports (/home/john/code/magellan-collections/node_modules/nyc/node_modules/default-require-extensions/js.js:8:9)
    at /home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4
    at require.extensions.(anonymous function) (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:405:12)
    at /home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4
    at require.extensions.(anonymous function) (/home/john/code/magellan-collections/node_modules/ts-node/src/index.ts:405:12)
    at Object.<anonymous> (/home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at /home/john/code/magellan-collections/node_modules/mocha/lib/mocha.js:253:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/home/john/code/magellan-collections/node_modules/mocha/lib/mocha.js:250:14)
    at Mocha.run (/home/john/code/magellan-collections/node_modules/mocha/lib/mocha.js:577:10)
    at Object.<anonymous> (/home/john/code/magellan-collections/node_modules/mocha/bin/_mocha:591:18)
    at Module._compile (module.js:660:30)
    at Module.replacementCompile (/home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:58:13)
    at module.exports (/home/john/code/magellan-collections/node_modules/nyc/node_modules/default-require-extensions/js.js:8:9)
    at Object.<anonymous> (/home/john/code/magellan-collections/node_modules/nyc/node_modules/append-transform/index.js:62:4)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at runMain (/home/john/.node-spawn-wrap-14957-e46fc629c0e4/node:68:10)
    at Function.<anonymous> (/home/john/.node-spawn-wrap-14957-e46fc629c0e4/node:171:5)
    at Object.<anonymous> (/home/john/code/magellan-collections/node_modules/nyc/bin/wrap.js:23:4)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at /home/john/.node-spawn-wrap-14957-e46fc629c0e4/node:178:8
    at Object.<anonymous> (/home/john/.node-spawn-wrap-14957-e46fc629c0e4/node:181:3)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at startup (bootstrap_node.js:193:16)
    at bootstrap_node.js:617:3

Here is the code that it says those properties aren’t defined in.

export abstract class Exception {
    public message: string;
    public name: string;

    constructor(message: string) {
        const ctor = (this as Object).constructor;

        Error.captureStackTrace(this, ctor);

        this.message = message;
        this.name = ctor.name;
    }
}

So they are definitely defined and also the line numbers don’t match up either. For the sake of completeness, here is the config for ts-node for mocha and how it is called.

/* config/mocha.config.js */
require('source-map-support/register');
const tsNode = require('ts-node');
tsNode.register({
    compilerOptions: {
        target: 'es5',
        module: 'commonjs',
        sourceMap: true
    } 
});

and the npm script that runs it,

"mocha": "nyc mocha -C --reporter spec config/mocha.config.js \"./src/**/*.spec.ts\""

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 25 (13 by maintainers)

Most upvoted comments

@blakeembrey I have created minimum repository that shows the error. Just clone and run yarn run build and error will happen.

https://github.com/ondratra/ts-node-bug-example