5

I'm new to TypeScript. I am trying to setup the use of it in WebStorm. I have created a tsconfig.json file in the root of my project and changed the builtin ts compiler to version 1.6.2. Still I need to include reference paths in every ts file. I hoped this would not be needed anymore once I defined the tsconfig.json file.

I tried to isolate the issue and went testing outside WebStorm. The issue remains. This is my setup: I installed TypeScript with "npm install -g typescript". I created a folder with this structure:

test\
  tsconfig.json
  src\
     file1.ts
     file2.ts

file2.ts uses a Class which is created in file1.ts.

When I run "tsc file2.ts" inside the src folder, I get a:

C:\data\tryout\tsconfig\src\file2.ts(11,20): error TS2095: Could not find symbol 'TodoCtrl'.

What do I need to do to get the compiler find all ts files automatically?

file1.ts:

module todos {
    'use strict';

    export class TodoCtrl {
        constructor() { }

        onTodos() {
                console.log('ok');
        }
    }
}

file2.ts:

// does work with ///<reference path='file1.ts' />
module todos {
    'use strict';

    export class DoneCtrl {
        constructor() { }

        onDone() {
            var test = new TodoCtrl();
        }
    }
}

result:

error TS2095: Could not find symbol 'TodoCtrl'.

I have put everything in a zip: https://www.dropbox.com/s/o4x52rddanhjqnr/tsconfig.zip?dl=0

2 Answers 2

5

Running tsc src\file2.ts will only use src\file2.ts as the input.

Run tsc in the directory with no input files for it to use the tsconfig.json, and input all .ts files in the directory and subdirectories.

As for why tsc src\file2.ts doesn't work. Your reference was missing a slash.

// <reference path='file1.ts' />

should be:

/// <reference path='file1.ts' />

Sign up to request clarification or add additional context in comments.

4 Comments

I used // to put the reference in comment. It works with the reference, but I do not want to use references.
If I issue tsc in the source folder without any arguments, I just get the usage info for tsc. Nothing is compiled.
I downloaded your ZIP. There were only two slashes in there.
Run tsc -v. I'm guessing that it's an older tsc.exe you're calling, and not tsc.cmd from npm.
1

I'm not sure if this will be relevant to your work but your zip contains an empty tsconfig.json. I filled it in with some options and actually was able to compile, both from the command line and from the editor.

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "rootDir": ".",
        "outDir": ".",
        "sourceMap": false
    },
    "filesGlob": [
        "./src/*.ts"
    ]
}

I hope this leads you somewhere.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.