1

I want TypeScript to allowJS and I want it to type check those files, so I add // @ts-check at the top of the files if they are *.js files. But I don't want the TypeScript compiler to copy those files to the output. I'll do that myself. I would be OK with TypeScript copying the *.js files but I would then want it to ignore files that are meant for building my site. Like the *.html.js files should be ignored and a helper file that I am using.

I put "src/**/*.html.js" in the tsconfig.json file but it still copies over those files. How can I stop TypeScript from copying those files?

I've tried ignoring "src/**/*.js" and "src/layouts/*" but neither works.

Here's my project. https://github.com/jon49/MealPlanner/blob/master/tsconfig.json#L31

2
  • What files should not be copied to /public? Or how do I see if it works? Commented May 19, 2020 at 11:14
  • Like the files in public\app\layouts that whole directory shouldn't be there. And the index.html.js file in public\app\meal-plans\edit. Thanks for taking a look at this! Commented May 19, 2020 at 15:43

1 Answer 1

1

So.. to be honest this is a bit out of the ordinary. I dont really understand your project structure, but I belive it could be way less complicated. Ive created a pull request with (I hope) fixes your issue, but bare in mind that my approch is based on a lot of assumptions. Ill detail my thought process and what I have done:


I figured that your project consists of a .ts part and a .js one. Youd like to build the .ts files (and emit those). The .js files however should be typechecked but not emited, since they get copied by some other script. You cannot emit only one part of your source files declared in your tsconfig, but you can specify if you want to emit anything - or just type check. Having said that, it is possible to create two ts.configs and spcify which one to use with the -p ( = --project) flag. Thus I created 2 tsconfigs, one for the .js files which will be typechecked but not emited (disabled via the noEmit: true - compiler option). And another for the .ts files. The run-scripts now execute both, the ts.tsconfig and js.tsconfig.

Sign up to request clarification or add additional context in comments.

8 Comments

Cool, I'll take a look at it after I get off of work today. The project structure is built around a multi-page application (MPA), offline first. It is just me learning a different way to build an app. I build the HTML with the index.html.js files. I don't want to make them with ts files as I want to reduce the complexity of the app and not have an intermediary build step to run the index.html.js files. I could use Deno, but then I'm adding another dependency on top of Nodejs and really with JSDoc it isn't that big of a deal. I've built other files with JS just for simplicity.
And like the web components are self contained so I didn't see a reason to make them ts files. It also reduces the build time. Eventually TypeScript should probably be rewritten in a compiled language as JS is just too slow.
@Jon49 Thats alright, didnt say it was necessarily bad, just uncommon. Also note that if you really want to take the build process into your own hands, you can always use the typescript api.
@Jon49 rewriting typescript as compiled language is a bit of a stetch, but sure, I believe Deno is trying to solve the setup problem.
Yeah, the guys from Deno are thinking about rewriting TypeScript in Rust. And then there is ESBuild which doesn't type check but compiles TypeScript. But, yes, I agree anyone taking on a project to port TypeScript to another language is in for a huge project. The bright side is that many of the lessons learned have been done already so it should be easier, I would hope. And hopefully they get yield working properly if they take it on.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.