mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Generate An Initial tsconfig File as a TypeScript TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1313 TILs and counting..._
|
||||
_1314 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -1212,6 +1212,7 @@ _1313 TILs and counting..._
|
||||
- [Create Union Type From Constants](typescript/create-union-type-from-constants.md)
|
||||
- [Extract Object Type Keys Into A Union Type](typescript/extract-object-type-keys-into-a-union-type.md)
|
||||
- [Extract Object Type Values Into A Union Type](typescript/extract-object-type-values-into-a-union-type.md)
|
||||
- [Generate An Initial tsconfig File](typescript/generate-an-initial-tsconfig-file.md)
|
||||
- [Generate Inferred Type From Zod Schema](typescript/generate-inferred-type-from-zod-schema.md)
|
||||
- [Get The Return Type Of An Async Function](typescript/get-the-return-type-of-an-async-function.md)
|
||||
- [Interfaces With The Same Name Are Merged](typescript/interfaces-with-the-same-name-are-merged.md)
|
||||
|
||||
48
typescript/generate-an-initial-tsconfig-file.md
Normal file
48
typescript/generate-an-initial-tsconfig-file.md
Normal file
@@ -0,0 +1,48 @@
|
||||
# Generate An Initial tsconfig File
|
||||
|
||||
A new `tsconfig.json` file can be generated using the `tsc` CLI which is part
|
||||
of the `typescript` node package.
|
||||
|
||||
You'll first want to add `typescript` to your project:
|
||||
|
||||
```bash
|
||||
$ npm install typescript --save-dev
|
||||
```
|
||||
|
||||
Since it is a local project dependency, you'll want to add `tsc` as a script in
|
||||
your `package.json`.
|
||||
|
||||
```json
|
||||
"scripts": {
|
||||
"tsc": "tsc"
|
||||
}
|
||||
```
|
||||
|
||||
Now you can use `npm` to run `tsc --init` like so:
|
||||
|
||||
```bash
|
||||
$ npm run tsc -- --init
|
||||
```
|
||||
|
||||
Notice the delimiting `--` which tells `npm` to pass the remaining arguments to
|
||||
the command being invoked. This makes sure `--init` gets passed as an argument
|
||||
to `tsc`.
|
||||
|
||||
This will generate a huge, mostly commented-out `tsconfig.json` file full of
|
||||
annotations that looks something like this:
|
||||
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
/* ... */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
/* ... */
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user