Skip to content

ts-node swallows errors for non-executed files (ambient type declarations, .d.ts, referenced but not required .ts) #853

Open
@alexeevg

Description

@alexeevg

Say I have a project with files:

index.d.ts:

export declare interface Foo {}

also, let's add some garbage here // invalid Typescript, this should not compile

example.spec.ts:

import {Foo} from '.';

describe('example', () => {
  it('should not compile', () => {
    const foo: Foo = {};
  });
});

Compilation of this project with tsc fails:

> tsc

index.d.ts:3:10 - error TS1005: ';' expected.

3 also, let's add some garbage here // this should not compile
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

index.d.ts:3:61 - error TS1002: Unterminated string literal.

3 also, let's add some garbage here // this should not compile

Found 2 errors.

But running the test with ts-node succeeds:

> mocha --require ts-node/register *.spec.ts

 example
    ✓ should not compile

  1 passing (13ms)

Expected behaviour: the test should fail with the same errors as tsc.

The problem, it seems, is in the way ts-node handles diagnostics only when emitting output for a given file, ignoring the errors in the imported modules: https://github.com/TypeStrong/ts-node/blob/master/src/index.ts#L357

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions