How to show types in js files VSCode like ts files - javascript

I have some files
Compenent.js
index.js
types.js
How i can avoid Type annotations can only be used in TypeScript files. error, and show types in js files?

Related

How to configure vite to allow JS in JSX files

I want to add a constants.js and utilFunctions.js files in my Vite-React (JSX) project but its giving me error of file format not correct
How can i config it so that it allows the JS files

angular project .js file generation configuration option

Please see this image. I see a constants.js file and "js.map" file under the constants.ts file. while I see no js file for other ts files. I understand that the type script compiler will generate the js file for each ts file. I am not sure why I can not see all the js files. I am not sure which configuration setting is affecting this. project is under source control. I only want to commit to the .ts files. I need to stop any ".js" or "js.map" files from being generated. not sure why it is only happening for one file. This is .Net core project with angular frontend.

Does the `tsc` command accept .d.ts files?

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".

Convert a JavaScript file back to it's TypeScript code using it's declaration and sourcemap file

I had a file, module.ts written in TypeScript and compiled it to JavaScript for production deployment. What was I left with were the following files;
module.js (the TypeScript code compiled into JavaScript)
module.d.ts (the declaration file)
module.js.map (the source file)
Now I want to revert the module.js back to module.ts file using all these 3 files because I don't have that .ts file anymore.
I tried loading module.js inside the browser, hoping it should load it's .ts file into the Developer Tools, using the Sourcemap, but it doesn't. I believe I am missing the point here of having a Sourcemap after all.

Angular 6 lib : how to export generated protobuf models?

I got 3 projects using a common-lib (in the same repository, multi-projects). common-lib exports common components/services/utils successfully.
But now, I want to also share here my generated protocol buffers ... but files are not included when I build the lib..
I think it's related to the fact that protobufs are JS files and not TS files (but declaration TS files are present)
Any help ?
public_api.ts :
export * from './lib/models/errors/ui'; // ok, it's a .ts file
export * from './lib/models/protobuf-generated/public/API_pb'; // ko, it's a .d.ts file and .js file
export * from './lib/models/protobuf-generated/public/API_pb_service'; // ko, it's a .d.ts file and .js file
generated protobufs folder :

Categories

Resources