I just downaloade TypeScript for Visual Studio 2015. I am writing .ts file and it created .js file in the same level in solution. Does anyone know how to hide the .js file or have it 'inside' .ts so I could just expand .ts tree and see .js?
You can configure your project to create .js files in a specific folder.
In VS 2015, you can set the build directory from "Redirect Javascript output to directory" in the typescript build section of your project properties page.
If you use a tsconfig.json the project property pages will all be grayed out but you can specify the directory in the tsconfig.json file:
"compilerOptions": {
"outDir": "./built",
Related
I'm adding package.json files in the main folders of my app to be able to import files easily, for example in constants folder there is a package.json file with {"name":"#constants"} and to import from the folder I use:
import file from '#constants'
This is very convenient, but when using Typescript I don't get error checking, autocomplete... for files imported these way.
I have a .d.ts file, and would like to compile it down to a .js file. Is this possible using the tsc command?
I know that the tsc command can take any .ts file and then compile it down .js file (I have tested this). However, I couldn't get it to take a .d.ts file as an input since it did not output any .js file for me.
I have tried to play around with tsconfig.json and this how my file looks like at the moment:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"outDir": "ali_output_javascript"
}
}
I also know the following about .d.ts and .ts files. Typescript declaration files (.d.ts) describe the shape of a JavaScript file. It allows you to use existing JavaScript code in TypeScript without having to write all the code in TypeScript. Typescript files (.ts) is just the standard file extension when writing in typescript.
From this medium article (https://medium.com/jspoint/typescript-compilation-the-typescript-compiler-4cb15f7244bc), it does say that TypeScript compilation looks for file extensions .ts and .d.ts:
Normally, you would use files or include option and provide file paths or glob patterns to include TypeScript files in the compilation process. However, you can drop the .ts extension from the glob pattern and let the TypeScript compiler search for the input files.
When a glob pattern doesn’t have a file extension, TypeScript looks for the files ending with .ts or .d.ts extension in the directory pointed by the glob pattern. The .d.ts file is a TypeScript declaration file, we have discussed this file type in the Declaration Files lesson (coming soon). When the allowJS compiler-option is set to true, the TypeScript will also search for .js files as well.
Please let me know if you any suggestions, and thank you for your time.
You misunderstood what .d.ts files are.
They are not supposed to be transpiled into .js files, .ts files are supposed to be transpiled into .js files and .d.ts files for strong typing in a JavaScript IDE, or for further use into a TypeScript project.
Also, .d.ts are not executable and cannot produce executable files as they are just empty shells with types, which is also know as ambient declaration, in TypeScript terms, which means "without implementation".
My project does not recognize the css and other files in the html files I have created, although I have written the extension paths correctly. How can I fix?
First of all you need to configure serving static files in Startup
app.UseStaticFiles(); //serves wwwroot by default
To serve your theme folder you need to add the following lines
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "theme")),
RequestPath = "/theme"
});
You did not put the correct path there. Your "style.css" is in 'theme/src/style.css' not in the 'theme/style.css'. Also use VS Code not Visual Studio because is useless if you create just files.
Also you did not provide all the files that are in the JS folder and CSS folder.
I have a project, it's not Angular2 or anything. I'm just using typescript in vscode.
I've setup my tsconfig.json to output my .ts files to a single file in ./build. However, for convenience purposes I would also like to include a folder or file i.e: /lib which contains all the js files I'm using such as linq (http://www.javascriptlinq.com/), jquery & bootstrap etc...
Basically, I want the end product of my project concists of 1 or 2 .js files.
Thanks to toskv in the rely, the workaround for me was to add
"allowJs": true
in tsconfig.json. Also,
"include": [ "src/**/*" ]
doesn't like it when i add folders deeper than that so i had to chuck them in
/src/lib
rather than
/src/lib/somelib/file.js
Can I get this result modifying tsconfig.json or package.json?
I want this structure:
angular2-quickstart
app
ts
app.component.ts
main.ts
js
app.component.js
app.component.js.map
main.js
main.js.map
index.html
license.md
no this:
angular2-quickstart
app
app.component.ts
main.ts
app.component.js
app.component.js.map
main.js
main.js.map
index.html
license.md
Yes, you can tell the TypeScript compiler to output .js files to a different directory using the outDir option in tsconfig.json, and I'd recommend setting the rootDir too so as to avoid unpleasant surprises in the future:
{
"compilerOptions": {
"outDir": "app/js",
"rootDir": "app/ts",
}
}
Don't forget to adjust paths in index.html.
If you want to separate out .js and .ts files in angular2, you have to follow only two steps:-
1) Add "outDir":"<folder name where you want to put your js Files>" within compilerOptions object in tsconfig.json file.
2) Map your folder in systemjs.config.js i.e modify the map object like
map:{
app:<Folder-Name which you have specified in outDir>
----
----
}