Why does it sometimes say it cannot find symbol define()?

My TypeScript (not javascript) is:

export class File {
    isOpenEnabled() {
        return false;
    }


    openClicked() {
        console.log('openClicked');
    }
}


define([], function () {
    return {
        handler: new File()
    };
});

And about half the time the "define" is in red (the other half not). The generated javascript is correct. and I do have require.d.ts installed.

??? - thanks - dave

5 comments

Hello!

Do you import it? Like '///<reference path='require.d.ts' />'?

0

I tried that and:
///<reference path='<ts-definitions>/require.d.ts' />
Neither worked (both references had a squiggly red underline for the filename).

Also, as a global reference in WebStorm, isn't that supposed to be automatically referenced?

??? - thanks - dave

0

It's even worse when I access code from Sencha Ext JS. In the case of Sencha we use the file extjs.d.ts that we have in the libs sub-folder while the RequireJS.d.ts is installed from the standard online location.

WebStorm_reference.png

0

The path in <reference path/> should match your actual path - please see the Typescript specification:
"
A comment of the form /// <reference path="…"/> adds a dependency on the source file specified in the path argument. The path is resolved relative to the directory of the containing source file"

So, if you have your extjs.d.ts in libs folder, the comments should look like

///<reference path='../../libs/extjs.d.ts' />

Note that WebStorm is smart enough to provide a completion for path inside <reference path/> :)
As for your RequireJS.d.ts, you need to also put it into your project directory and provide a correct rtelative path to it in reference path comment

>Also, as a global reference in WebStorm, isn't that supposed to be automatically referenced?

javascript libraries in WebStorm are only used by WebStorm itself - for type hinting, error highlighting, navigation. But they are available neither to compiler nor to the browser. So, you have to make sure to place all needed files to the project folder to be able to compile and execute your code

0

Ok, this is making no sense. I just opened this up again and now it is all fine. Nothing red.

And then after 40 seconds - all red again.

It all compiles and runs fine. It just says there were errors in the WebStorm syntax checking.

It's all good now with the relative reference. Sorry for all the questions on this - I assumed that when I set the project settings to say where the .ts files are, that covered everything.

This is all answered now.

thanks - dave

0

Please sign in to leave a comment.