I want to investigate certain inferred types in TypeScript code. This would be especially useful in case of correct files to be sure that inferred types are specific enough, exact and correct.
Given TypeScript file how to get type at specific position in it, in similar manner to flow type-at-pos?
I don't need any additional complex tooling beyond this, like IDE integrations. Just this simple functionality.
Unfortunately TypeScript doesn't expose anything like this in an easy-to-consume manner. TypeScript does have a language server that you can use to query for type information. It's relatively easy to do, but is cumbersome. Basically you launch the server and send some commands to open a project and file, then send a command to request info.
If you have typescript installed globally (npm install -g typescript) you should be able to run the typescript server under the tsserver executable. Otherwise, you can run it by locating it inside the bin folder within the typescript module.
Commands are sent from stdin and responses are sent via stdout. The commands are just JSON and terminated with a new line.
The first command you'll want to send is openExternalProject:
{"type":"request","command":"openExternalProject","arguments":{"projectFileName":"/path/to/tsconfig.json","rootFiles":[],"options":{}}}
Replace /path/to/tsconfig.json with the path to your tsconfig.json file.
The next command is to open a file:
{"type":"request","command":"open","arguments":{"file":"/path/to/file.ts"}}
And the final command to get type information is quickinfo:
{"type":"request","command":"quickinfo","arguments":{"offset":9,"line":5,"file":"/path/to/file.ts"}}
Replace the line value with the line of the type you want info on, and the offset to the line offset.
You should get a response from the server similar to this:
{"seq":0,"type":"response","command":"quickinfo","success":true,"body":{"kind":"alias","kindModifiers":"","start":{"line":5,"offset":8},"end":{"line":5,"offset":19},"displayString":"(alias) const MyComponent: new () => MyComponent\nimport MyComponent","documentation":"","tags":[]}}
Here's my complete request/response when I tested this:
> ./tsserver
Content-Length: 76
{"seq":0,"type":"event","event":"typingsInstallerPid","body":{"pid":63491}}
{"type":"request","command":"openExternalProject","arguments":{"projectFileName":"/test/tsconfig.json","rootFiles":[],"options":{}}}
Content-Length: 526
{"seq":0,"type":"event","event":"telemetry","body":{"telemetryEventName":"projectInfo","payload":{"projectId":"489d647358fb01382e6efc991212c7fd2bd8d16a91e6b960aa17b2c86ff9cb25","fileStats":{"js":0,"jsSize":0,"jsx":0,"jsxSize":0,"ts":0,"tsSize":0,"tsx":0,"tsxSize":0,"dts":0,"dtsSize":0,"deferred":0,"deferredSize":0},"compilerOptions":{},"typeAcquisition":{"enable":true,"include":false,"exclude":false},"compileOnSave":true,"configFileName":"other","projectType":"external","languageServiceEnabled":true,"version":"3.7.2"}}}
Content-Length: 87
{"seq":0,"type":"response","command":"openExternalProject","success":true,"body":true}
Content-Length: 415
{"seq":0,"type":"event","event":"setTypings","body":{"projectName":"/test/tsconfig.json","typeAcquisition":{"include":[],"exclude":[],"enable":true},"compilerOptions":{"allowNonTsExtensions":true,"noEmitForJsFiles":true},"typings":["/Users/so-test/Library/Caches/typescript/3.7/node_modules/#types/react/index.d.ts"],"unresolvedImports":[],"kind":"action::set"}}
Content-Length: 415
{"seq":0,"type":"event","event":"setTypings","body":{"projectName":"/test/tsconfig.json","typeAcquisition":{"include":[],"exclude":[],"enable":true},"compilerOptions":{"allowNonTsExtensions":true,"noEmitForJsFiles":true},"typings":["/Users/so-test/Library/Caches/typescript/3.7/node_modules/#types/react/index.d.ts"],"unresolvedImports":[],"kind":"action::set"}}
{"type":"request","command":"open","arguments":{"file":"/test/App.tsx"}}
Content-Length: 272
{"seq":0,"type":"event","event":"projectLoadingStart","body":{"projectName":"/test/tsconfig.json","reason":"Creating possible configured project for /test/App.tsx to open"}}
Content-Length: 150
{"seq":0,"type":"event","event":"projectLoadingFinish","body":{"projectName":"/test/tsconfig.json"}}
Content-Length: 239
{"seq":0,"type":"event","event":"configFileDiag","body":{"triggerFile":"/test/App.tsx","configFile":"/test/tsconfig.json","diagnostics":[]}}
{"type":"request","command":"quickinfo","arguments":{"offset":9,"line":5,"file":"/test/App.tsx"}}
Content-Length: 283
{"seq":0,"type":"response","command":"quickinfo","success":true,"body":{"kind":"alias","kindModifiers":"","start":{"line":5,"offset":8},"end":{"line":5,"offset":19},"displayString":"(alias) const MyComponent: new () => MyComponent\nimport MyComponent","documentation":"","tags":[]}}
There may be a more efficient way to query the language server, but this is what I came up with in the short amount of time I fiddled with it.
You can look at all the possible request/responses here: https://github.com/Microsoft/TypeScript/blob/master/lib/protocol.d.ts
Hope this helps.
I have the following folder structure:
C:\xampp\htdocs\project
Inside project folder, I have an index.html file and other folders which contain js files and minified versions of angular and angular-route.
I installed XAMPP and I started all the modules(MySQL, FileZilla, Mercury, Tomcat), only Apache doesn't start, throwind these messages:
5:14:15 PM [Apache] Status change detected: stopped
5:14:15 PM [Apache] Error: Apache shutdown unexpectedly.
5:14:15 PM [Apache] This may be due to a blocked port, missing dependencies,
5:14:15 PM [Apache] improper privileges, a crash, or a shutdown by another method.
5:14:15 PM [Apache] Press the Logs button to view error logs and check
5:14:15 PM [Apache] the Windows Event Viewer for more clues
5:14:15 PM [Apache] If you need more help, copy and post this
5:14:15 PM [Apache] entire log window on the forums
I'm trying to see the index.html file in a browser, I use this URL: http://localhost/xampp/htdocs/project/index.html but I get an empty page, in console showing this message:
GET http://localhost/xampp/htdocs/project/index.html 404 (Not Found)
Any ideas how to solve this?
The URL you are trying to navigate to is not correct. It should be localhost/project/index.html#/. Basically, xampp sets up a server (apache and others) in your system. And your file for a project such as index.html should reside in the xampp\htdocs\YourFolderName.
The browser locates the server in localhost and will search through the above folder for any resources available in there. So the url will for above case will be localhost/YourFolderName/index.html#/
I'm part of a development team who works on a single page application that's becoming a nightmare to develop. At the moment our build minifies all the JS files into one file so once it's deployed it's fast and easy to cache but when developing we have over 2000 individual JS files that need to be downloaded every time you refresh.
Has anyone come across this issue themselves and found a workaround.
One solution I was thinking was that if you could cache every file, but every time you save the file it would also break the cache just for that file.
A tactic people are using at the moment is to slim down their workspaces but that takes a huge amount of time as there are so many dependencies.
Any help on this would be very much appreciated
The problem is that when you're doing F5 or Ctrl+R (or using you're browser inspect tool), the headers sent to get the file asks for no cache for every file, and interprete all JS, assuming you're working on a browser project.
A possible easy to set up solution would be to make a small dedicated HTTP server which looks at the modification date of the file to serve and which returns only an 304 Not Modified header even if the browser specifies a if-modified-since header (which means that the file requested is cached by the browser).
Scenario:
The client asks for JS files (for the second time) with a if-modified-since: Wed, 09 Dec 2015 12:18:00 GMT header to your localhost:8888
If the file on disk is less recent, file server sends a 304 header
If the file is newer so the file server streams the file, specifying Date: Wed, 09 Dec 2015 12:20:00 GMT and cache-control: public, max-age:3600, must-revalidate
Edit: so this is a tiny NodeJS file server. Just install NodeJS, add npm. Create this file as index.js, set the wwwpath variable, run npm install node-static in the same folder as index.js (it is a dependency of the file server below), and execute the program with nodejs index.js (or node index.js on Windows).
var static = require('node-static');
var fs = require('fs');
var wwwpath = './www';
var fileServer = new static.Server(wwwpath);
require('http').createServer(function (request, response) {
request.addListener('end', function () {
fileServer.serve(request, response, function (err, result) {
var filepath = wwwpath + request.url;
// browser is checking cache
if (request.headers && request.headers['if-modified-since']) {
var ifModifiedSince = new Date(request.headers['if-modified-since']);
var stats = fs.statSync(filepath);
// file has been edited since
if (stats.mtime.getTime() > (ifModifiedSince.getTime() + 1000)) { // +1000 Date header is no millisecond accurate
response.writeHead(304, 'Not Modified');
response.end();
}
}
// file not found / ...
if (err) {
response.writeHead(err.status, err.headers);
response.end();
}
});
}).resume();
}).listen(8080);
What does it do ? If you have a file myscript.js in wwwroot, call it with http://localhost:8080/myscript.js. If you refresh your page, the server will check the edit time of the file before streaming it.
So basically, I have the following situation going on: I have a nodejs server running on port 80 and an apache server on port 8080 (the apache server is used for executing php files to a mysql database).
Everything is working fine, unless the nodejs server is down. The client can't get the main index.html file (or any file for that matter) , and therefore can't execute code which includes catching an ERR_CONNECTION_REFUSED error, thrown by the client. When the server is down, I would like to reroute the client to a page with the port :8080 behind the url, where the users can see that the server is down.
My question is how do I do this?
Thank you very kindly,
Zeno
EDIT: apache error:
[Sat May 23 22:09:46.096365 2015] [ssl:warn] [pid 5020:tid 324] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Sat May 23 22:09:46.112376 2015] [proxy_html:notice] [pid 5020:tid 324] AH01425: I18n support in mod_proxy_html requires mod_xml2enc. Without it, non-ASCII characters in proxied pages are likely to display incorrectly.
[Sat May 23 22:09:46.189482 2015] [core:warn] [pid 5020:tid 324] AH00098: pid file D:/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Sat May 23 22:09:46.195484 2015] [proxy_balancer:emerg] [pid 5020:tid 324] AH01177: Failed to lookup provider 'shm' for 'slotmem': is mod_slotmem_shm loaded??
[Sat May 23 22:09:46.195484 2015] [:emerg] [pid 5020:tid 324] AH00020: Configuration Failed, exiting
You should be able to specify a fallback resource in cases where one resource is not available:
FallbackResource /index.php
This can be placed in an .htaccess file or within your apache config.
https://www.adayinthelifeof.nl/2012/01/21/apaches-fallbackresource-your-new-htaccess-command/
To handle the node server being down, you would need to have setup a reverse proxy server using apache or nginx. Then you can specify a fallback resource in case the place your proxy points to is down.
This is how to setup a reverse proxy in apache with fallback via balancer.
https://serverfault.com/q/87507/193671
I have facing strange problem. I have deployed images and js file in Apache Tomcat directrory but it is not showing on page and a warning is coming up:
Resource interpreted as Image but transferred with MIME type text/html: "http://localhost:8084/webApp/img/access.jpg".
Earlier it was working fine but now jquery is also not working and the following error is coming up:
Uncaught ReferenceError: jQuery is not defined
Earlier this error message was appearing in Firefox but Chrome was working fine. But now it is showing the error in Chrome as well.
I have also tried to use the absolute path but no success.
<script src="/webApp/jquery-1.7.2.min.js"></script>
<img src="http://localhost:8084/webApp/img/access.jpg"/>
If you are using tomcat, you should locate the resources at $CATALINA_HOME/webapps/ROOT folder. From there, you might have access to the files.
You can check the access permissions from terminal. If you use unix / linux, locate to the folder:
cd $CATALINA_HOME/webapps/ROOT
And execute the command:
ls -la
This means it can be accessed by everyone, so should be available to everyone accessing to the server by browser
drwxr-x**r-x#** 22 user staff 704 11 jun 01:25 .
You could also try changing the permisions, but your server would be unsure:
sudo chmod a+rx webApp/img/access.jpg
Or go to the webApp folder via cd and execute
sudo chmod -R a+rx .
Deppending on your preferences (the last one means giving permission to all resources on webApp folder, what means givving access to all your projects in server, quite unsure...).
Hope it helps somebody.