Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate typescript, but don't build it

I have a folder called "__ tests __".

I want it to be validated as typescript, but I don't want to build that folder. ( I don't want it to go to dist folder )

How would I do that?

It's like I have to include it, but not really...

My ts.config.json:

{
    "compilerOptions": {
        "module": "CommonJS",
        "target": "ES2017",
        "noImplicitAny": true,
        "preserveConstEnums": true,
        "outDir": "./dist",
        "sourceMap": true,
        "esModuleInterop": true,
        "resolveJsonModule": true
    },
    "include": ["src/**/*", "src/**/*.json", "__tests__/**/*"],
    "exclude": ["node_modules", "**/*.spec.ts"]
}
like image 1000
Djordje Nikolic Avatar asked Mar 01 '23 20:03

Djordje Nikolic


1 Answers

You can simply use the option noEmit in your use case to not emit the output.

{
  "compilerOptions": {
    // ...
    "noEmit": true,
  }
}

Update for only emitting in test case

I think you can also go for creating the new configuration for testing files to include only your test code extending from the current one.

tsconfig.test.json

{
  "extends": "./tsconfig.json",
  {
   "compilerOptions": {
      "noEmit": true,
    },
   "include": [
      "__tests__", // your test file
   ],
  }
}

package.json

{
  "scripts": {
    "build": "tsc",
    "test:typeCheck": "tsc --project tsconfig.test.json"
  }
}
  • Type check your test folder without emitting: npm run test:typeCheck
  • Run build to emit files normally: npm build
like image 57
tmhao2005 Avatar answered Mar 13 '23 03:03

tmhao2005