Question

I've been bumbling around attempting to upgrade a fork of Basarat Ali Syed's excellent typescript editor project to Typescript 1.0 RTM.

Out of the box the project works without issue however it's using a year old version of typescript and the compiler api has changed quite a bit since then.

To update the project I dropped in the new typescript bits (lib.d.ts and typescriptServices.js) and set about fixing things that were broken due to api changes.

I'm at a point where things compile and the compile errors are surfacing on the ace editor but I can't figure out why globals such as document, alert, window, setTimeout, etc are no longer recognized:

typescript compilation issue

There must be something simple I'm missing, it's so close to working. Anyone have any ideas?

Thanks!

Was it helpful?

Solution

took a look at the code here: https://typescript.codeplex.com/SourceControl/latest#src/compiler/tsc.ts

when compiling it's adding the lib.d.ts to the compiler's list of files, just like any other file:

resolve() :

        if (includeDefaultLibrary) {
            var libraryResolvedFile: IResolvedFile = {
                path: this.getDefaultLibraryFilePath(),
                referencedFiles: [],
                importedFiles: []
            };

            // Prepend the library to the resolved list
            resolvedFiles = [libraryResolvedFile].concat(resolvedFiles);
        }

compile() :

        this.resolvedFiles.forEach(resolvedFile => {
            var sourceFile = this.getSourceFile(resolvedFile.path);
            compiler.addFile(resolvedFile.path, sourceFile.scriptSnapshot, sourceFile.byteOrderMark, /*version:*/ 0, /*isOpen:*/ false, resolvedFile.referencedFiles);
        });

once I started doing the same the compilation errors went away. must be this step wasn't necessary in older versions of the compiler?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top