Comments (7)
Have a look here
https://github.com/nwolverson/tstooltip/blob/master/worker/worker.ts#L55
I basically used the same thing and loaded the lib.d.ts
initially (if I wrote this now I'd load it via a bundler instead of directly xhr).
Otherwise depending what you're doing you may wish to turn the lib check off or whatever the option is.
(Obviously the problem with an in-memory host is you need to get the lib file into memory to use it...)
from blog-typescript-api.
Thanks for the quick response!
I didn't have lib.d.ts
in memory. I assumed the compiler would do that for me because of the getDefaultLibFileName()
/ getDefaultLibFileLocation()
methods.
So thanks a lot!
I do have 1 more issue though:
It doesn't seem to be able to recognize import statements. When I try to compile the following:
import Calculator from "./calculator";
class HelloWorld {
private calculator: Calculator;
constructor() {this.calculator = new Calculator();}
public sayHelloTo(name: string) {
console.log("Hello " + name);
}
}
I still get the following output:
Cannot find module './calculator'.
The file calculator.ts
is in the same folder and gets included in the compilerHost. It looks like this:
export default class Calculator {
constructor() {}
// more logic down here
}
Do you have any idea how I get the CompilerHost to recognize this situation?
from blog-typescript-api.
Btw, initial question is answered! Thanks a lot for that!
Closing issue.
from blog-typescript-api.
If you have files in a folder actually on disk you may want to look into using the default compiler host, I think there's some helper that returns one.
from blog-typescript-api.
The thing is, I already have the file in memory. I don't want to read/write from/to disk in my proces, because I will be changing the files a lot. That would take too long.
from blog-typescript-api.
@Thomasp24 sure, then in that case loading all the files into the CompilerHost
would seem to be the right thing, I'm not sure how path resolution works but need to get the right paths, I guess.
You might want to look at the LanguageService
API if it's more appropriate to your use case, being designed for editors etc which will make lots of updates to existing set of files.
from blog-typescript-api.
Just an update, I changed all the file paths to their absolute path.
so: "./calculator.ts"
get changed to "Users/thomasp/Desktop/projectfolder/calculator.ts"
before being added to the CompilerHost by calling this.compilerHost.addFile()
.
I geuss import statements do this automatically.
This seemed to have fixed the issue.
from blog-typescript-api.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog-typescript-api.