Skip to content

Commit 72e3d55

Browse files
committed
Add Generate An Initial tsconfig File as a TypeScript TIL
1 parent 6f99af3 commit 72e3d55

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1313 TILs and counting..._
13+
_1314 TILs and counting..._
1414

1515
---
1616

@@ -1212,6 +1212,7 @@ _1313 TILs and counting..._
12121212
- [Create Union Type From Constants](typescript/create-union-type-from-constants.md)
12131213
- [Extract Object Type Keys Into A Union Type](typescript/extract-object-type-keys-into-a-union-type.md)
12141214
- [Extract Object Type Values Into A Union Type](typescript/extract-object-type-values-into-a-union-type.md)
1215+
- [Generate An Initial tsconfig File](typescript/generate-an-initial-tsconfig-file.md)
12151216
- [Generate Inferred Type From Zod Schema](typescript/generate-inferred-type-from-zod-schema.md)
12161217
- [Get The Return Type Of An Async Function](typescript/get-the-return-type-of-an-async-function.md)
12171218
- [Interfaces With The Same Name Are Merged](typescript/interfaces-with-the-same-name-are-merged.md)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Generate An Initial tsconfig File
2+
3+
A new `tsconfig.json` file can be generated using the `tsc` CLI which is part
4+
of the `typescript` node package.
5+
6+
You'll first want to add `typescript` to your project:
7+
8+
```bash
9+
$ npm install typescript --save-dev
10+
```
11+
12+
Since it is a local project dependency, you'll want to add `tsc` as a script in
13+
your `package.json`.
14+
15+
```json
16+
"scripts": {
17+
"tsc": "tsc"
18+
}
19+
```
20+
21+
Now you can use `npm` to run `tsc --init` like so:
22+
23+
```bash
24+
$ npm run tsc -- --init
25+
```
26+
27+
Notice the delimiting `--` which tells `npm` to pass the remaining arguments to
28+
the command being invoked. This makes sure `--init` gets passed as an argument
29+
to `tsc`.
30+
31+
This will generate a huge, mostly commented-out `tsconfig.json` file full of
32+
annotations that looks something like this:
33+
34+
```json
35+
{
36+
"compilerOptions": {
37+
/* Visit https://aka.ms/tsconfig to read more about this file */
38+
39+
/* Projects */
40+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
41+
/* ... */
42+
43+
/* Language and Environment */
44+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
45+
/* ... */
46+
}
47+
}
48+
```

0 commit comments

Comments
 (0)