Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to emit parts of code without transpiling or type-checking = a comment to turn off TypeScript #5567

Closed
niieani opened this issue Nov 9, 2015 · 3 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@niieani
Copy link

niieani commented Nov 9, 2015

It would be great to have the option to emit certain code as is, without the tsc touching it or analyzing it.
I'd imagine it could be achieved with a simple, special comment that the TypeScript transpiler would understand, e.g.:

// normal TypeScript code...

/// <no-compile>
'whatever is here will just get copied to the output .js file, without being touched';
/// </no-compile>

// more proper TypeScript code...

My use case and reasoning is the following:

I'm currently using a dual transpiling stack:
TS -> ES6 (via TS) -> ES6 (via Babel).

This works great, but Babel has some nice new ES2016 features that TypeScript probably won't have for a year or more. It would be great if we could write using those features, surround them with such no-compile comments so that only those would not get transpiled or analyzed by TS. Babel could take care of them in the next stage of transpilation pipeline.
There might be other reasonable use-cases for the ability to turn off TypeScript for a part of code.

Partially related to these, but I'd imagine this would be much simpler to implement:

@mhegazy mhegazy added the Duplicate An existing issue was already created label Nov 9, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Nov 9, 2015

for these files, write them separately and create a .d.ts for them, and do not pass in the .js files to the TypeScript compiler.

@mhegazy mhegazy added Question An issue which isn't directly actionable in code and removed Duplicate An existing issue was already created labels Nov 9, 2015
@mhegazy mhegazy closed this as completed Nov 13, 2015
@twome
Copy link

twome commented Jul 25, 2016

Here is a different use-case: if the you have an extremely large and complex .d.ts file, such as one for Angular, and the file is mostly fine but has occasional small errors in them which block you from writing perfectly legitimate code. Let's assume this file is so large and so complex that finding the method that's troubling you, figuring out the syntax/structure, and properly fixing the error would be a sizeable waste of time.

You could still write declare let angular: any at the head of the file, but then that will disable type checking for all the times you reference Angular within that file, not just the few lines or particular method you care about.

Do you think that's a valid use-case?

@mhegazy
Copy link
Contributor

mhegazy commented Jul 25, 2016

Declaration correctness is an issue that should be solved on the producer side, in your example angular team for angular2 or definitely typed for angular1.
If the file has errors, you copy them locally, change the declarations to either stub out parts you do not care about or fixing the declarations. from the compiler perspective all errors are equal, regardless if they come from a file you wrote, or a file you acquired form definitely typed.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants