├── .gitignore
├── .prettierrc.json
├── README.md
├── errors
└── includes
│ ├── TS17xxx
│ ├── TS17000.md
│ ├── TS17004.md
│ └── TS17009.md
│ ├── TS18xxx
│ ├── TS18004.md
│ ├── TS18016.md
│ ├── TS18046.md
│ └── TS18048.md
│ ├── TS1xxx
│ ├── TS1002.md
│ ├── TS1005.md
│ ├── TS1006.md
│ ├── TS1015.md
│ ├── TS1016.md
│ ├── TS1029.md
│ ├── TS1036.md
│ ├── TS1038.md
│ ├── TS1039.md
│ ├── TS1046.md
│ ├── TS1055.md
│ ├── TS1056.md
│ ├── TS1064.md
│ ├── TS1066.md
│ ├── TS1068.md
│ ├── TS1070.md
│ ├── TS1095.md
│ ├── TS1103.md
│ ├── TS1109.md
│ ├── TS1117.md
│ ├── TS1127.md
│ ├── TS1128.md
│ ├── TS1149.md
│ ├── TS1155.md
│ ├── TS1160.md
│ ├── TS1183.md
│ ├── TS1192.md
│ ├── TS1196.md
│ ├── TS1202.md
│ ├── TS1208.md
│ ├── TS1218.md
│ ├── TS1219.md
│ ├── TS1225.md
│ ├── TS1228.md
│ ├── TS1243.md
│ ├── TS1244.md
│ ├── TS1254.md
│ ├── TS1259.md
│ ├── TS1308.md
│ ├── TS1337.md
│ ├── TS1341.md
│ ├── TS1355.md
│ ├── TS1357.md
│ ├── TS1361.md
│ ├── TS1363.md
│ ├── TS1368.md
│ ├── TS1371.md
│ ├── TS1375.md
│ ├── TS1378.md
│ ├── TS1385.md
│ ├── TS1389.md
│ ├── TS1431.md
│ ├── TS1432.md
│ ├── TS1434.md
│ └── TS1471.md
│ ├── TS2xxx
│ ├── TS2300.md
│ ├── TS2304.md
│ ├── TS2305.md
│ ├── TS2306.md
│ ├── TS2307.md
│ ├── TS2314.md
│ ├── TS2315.md
│ ├── TS2322.md
│ ├── TS2335.md
│ ├── TS2339.md
│ ├── TS2344.md
│ ├── TS2345.md
│ ├── TS2348.md
│ ├── TS2349.md
│ ├── TS2351.md
│ ├── TS2352.md
│ ├── TS2355.md
│ ├── TS2361.md
│ ├── TS2362.md
│ ├── TS2364.md
│ ├── TS2365.md
│ ├── TS2366.md
│ ├── TS2367.md
│ ├── TS2368.md
│ ├── TS2369.md
│ ├── TS2370.md
│ ├── TS2371.md
│ ├── TS2372.md
│ ├── TS2377.md
│ ├── TS2378.md
│ ├── TS2390.md
│ ├── TS2391.md
│ ├── TS2394.md
│ ├── TS2395.md
│ ├── TS2403.md
│ ├── TS2411.md
│ ├── TS2420.md
│ ├── TS2428.md
│ ├── TS2430.md
│ ├── TS2440.md
│ ├── TS2445.md
│ ├── TS2448.md
│ ├── TS2451.md
│ ├── TS2454.md
│ ├── TS2456.md
│ ├── TS2459.md
│ ├── TS2475.md
│ ├── TS2476.md
│ ├── TS2488.md
│ ├── TS2497.md
│ ├── TS2503.md
│ ├── TS2507.md
│ ├── TS2511.md
│ ├── TS2512.md
│ ├── TS2515.md
│ ├── TS2528.md
│ ├── TS2531.md
│ ├── TS2532.md
│ ├── TS2533.md
│ ├── TS2538.md
│ ├── TS2540.md
│ ├── TS2550.md
│ ├── TS2551.md
│ ├── TS2552.md
│ ├── TS2554.md
│ ├── TS2556.md
│ ├── TS2558.md
│ ├── TS2559.md
│ ├── TS2564.md
│ ├── TS2567.md
│ ├── TS2571.md
│ ├── TS2574.md
│ ├── TS2577.md
│ ├── TS2580.md
│ ├── TS2582.md
│ ├── TS2583.md
│ ├── TS2584.md
│ ├── TS2588.md
│ ├── TS2595.md
│ ├── TS2611.md
│ ├── TS2613.md
│ ├── TS2616.md
│ ├── TS2636.md
│ ├── TS2637.md
│ ├── TS2652.md
│ ├── TS2654.md
│ ├── TS2656.md
│ ├── TS2661.md
│ ├── TS2663.md
│ ├── TS2664.md
│ ├── TS2665.md
│ ├── TS2668.md
│ ├── TS2669.md
│ ├── TS2677.md
│ ├── TS2678.md
│ ├── TS2680.md
│ ├── TS2683.md
│ ├── TS2684.md
│ ├── TS2686.md
│ ├── TS2687.md
│ ├── TS2689.md
│ ├── TS2691.md
│ ├── TS2693.md
│ ├── TS2694.md
│ ├── TS2695.md
│ ├── TS2706.md
│ ├── TS2709.md
│ ├── TS2713.md
│ ├── TS2715.md
│ ├── TS2717.md
│ ├── TS2720.md
│ ├── TS2722.md
│ ├── TS2724.md
│ ├── TS2730.md
│ ├── TS2732.md
│ ├── TS2739.md
│ ├── TS2740.md
│ ├── TS2741.md
│ ├── TS2742.md
│ ├── TS2749.md
│ ├── TS2769.md
│ ├── TS2774.md
│ ├── TS2779.md
│ ├── TS2786.md
│ ├── TS2790.md
│ ├── TS2792.md
│ ├── TS2794.md
│ ├── TS2813.md
│ └── TS2814.md
│ ├── TS4xxx
│ ├── TS4020.md
│ ├── TS4025.md
│ ├── TS4060.md
│ ├── TS4063.md
│ ├── TS4075.md
│ ├── TS4081.md
│ ├── TS4104.md
│ ├── TS4112.md
│ ├── TS4113.md
│ └── TS4114.md
│ ├── TS5xxx
│ ├── TS5023.md
│ ├── TS5024.md
│ ├── TS5025.md
│ ├── TS5042.md
│ ├── TS5054.md
│ ├── TS5055.md
│ ├── TS5058.md
│ ├── TS5069.md
│ ├── TS5070.md
│ ├── TS5083.md
│ ├── TS5087.md
│ └── TS5101.md
│ ├── TS6xxx
│ ├── TS6053.md
│ ├── TS6059.md
│ ├── TS6133.md
│ ├── TS6138.md
│ ├── TS6196.md
│ ├── TS6198.md
│ └── TS6504.md
│ ├── TS7xxx
│ ├── TS7006.md
│ ├── TS7008.md
│ ├── TS7009.md
│ ├── TS7010.md
│ ├── TS7016.md
│ ├── TS7017.md
│ ├── TS7022.md
│ ├── TS7023.md
│ ├── TS7026.md
│ ├── TS7027.md
│ ├── TS7030.md
│ ├── TS7031.md
│ ├── TS7034.md
│ ├── TS7041.md
│ ├── TS7044.md
│ └── TS7053.md
│ ├── TS80xxx
│ └── TS80005.md
│ └── TS8xxx
│ └── TS8020.md
├── lefthook.yml
├── package-lock.json
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | node_modules/
3 |
--------------------------------------------------------------------------------
/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/prettierrc",
3 | "arrowParens": "avoid",
4 | "bracketSameLine": false,
5 | "bracketSpacing": false,
6 | "endOfLine": "lf",
7 | "printWidth": 120,
8 | "proseWrap": "never",
9 | "requirePragma": false,
10 | "semi": true,
11 | "singleAttributePerLine": true,
12 | "singleQuote": true,
13 | "tabWidth": 2,
14 | "trailingComma": "es5",
15 | "useTabs": false
16 | }
17 |
--------------------------------------------------------------------------------
/errors/includes/TS17xxx/TS17000.md:
--------------------------------------------------------------------------------
1 | ## TS17000
2 |
3 | > error TS17000: JSX attributes must only be assigned a non-empty 'expression'.
4 |
5 | ### Broken Code ❌
6 |
7 | ```tsx
8 |
My App!
; 10 | } 11 | 12 | export default App; 13 | ``` 14 | 15 | ### Fixed Code ✔️ 16 | 17 | You have to add a configuration for "jsx" to your "tsconfig.json" file: 18 | 19 | 20 | {% codeblock lang:json tsconfig.json %} 21 | { 22 | "compilerOptions": { 23 | "jsx": "react" 24 | } 25 | } 26 | {% endcodeblock %} 27 | 28 | -------------------------------------------------------------------------------- /errors/includes/TS17xxx/TS17009.md: -------------------------------------------------------------------------------- 1 | ## TS17009 2 | 3 | > error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. 4 | 5 | ### Broken Code ❌ 6 | 7 | ```ts 8 | abstract class Animal { 9 | abstract name: string; 10 | } 11 | 12 | class Dog extends Animal { 13 | public name; 14 | 15 | constructor(name: string) { 16 | this.name = name; 17 | super(); 18 | } 19 | } 20 | ``` 21 | 22 | ### Fixed Code ✔️ 23 | 24 | 25 | {% codeblock lang:ts mark:9 %} 26 | abstract class Animal { 27 | abstract name: string; 28 | } 29 | 30 | class Dog extends Animal { 31 | public name; 32 | 33 | constructor(name: string) { 34 | super(); 35 | this.name = name; 36 | } 37 | } 38 | {% endcodeblock %} 39 | 40 | -------------------------------------------------------------------------------- /errors/includes/TS18xxx/TS18004.md: -------------------------------------------------------------------------------- 1 | ## TS18004 2 | 3 | > error TS18004: No value exists in scope for the shorthand property '`age`'. Either declare one or provide an initializer. 4 | 5 | ### Broken Code ❌ 6 | 7 | ```ts 8 | export function getPerson() { 9 | return { 10 | age, 11 | fistName: 'Benny', 12 | lastName: 'Neugebauer', 13 | }; 14 | } 15 | ``` 16 | 17 | ### Fixed Code ✔️ 18 | 19 | If you want to use the **shorthand property name syntax** to access the `age` property, you have to make sure that this variable is defined in the first place: 20 | 21 | ```ts 22 | export function getPerson() { 23 | const age = 34; 24 | return { 25 | age, 26 | fistName: 'Benny', 27 | lastName: 'Neugebauer', 28 | }; 29 | } 30 | ``` 31 | 32 | Alternatively, you can avoid using the **shorthand property name syntax**: 33 | 34 | ```ts 35 | export function getPerson() { 36 | return { 37 | age: 34, 38 | fistName: 'Benny', 39 | lastName: 'Neugebauer', 40 | }; 41 | } 42 | ``` 43 | -------------------------------------------------------------------------------- /errors/includes/TS18xxx/TS18016.md: -------------------------------------------------------------------------------- 1 | ## TS18016 2 | 3 | > error TS18016: Private identifiers are not allowed outside class bodies. 4 | 5 | ### Broken Code ❌ 6 | 7 | ```ts 8 | interface Person { 9 | #age: number; 10 | } 11 | ``` 12 | 13 | ### Fixed Code ✔️ 14 | 15 | Private properties can only be used in classes but not in interfaces. We therefore need to convert the interface into a class in order to be able to compile the code: 16 | 17 | ```ts 18 | class Person { 19 | #age: number; 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /errors/includes/TS18xxx/TS18046.md: -------------------------------------------------------------------------------- 1 | ## TS18046 2 | 3 | > error TS18046: '`error`' is of type '`unknown`'. 4 | 5 | ### Broken Code ❌ 6 | 7 | 8 | {% codeblock mark:5 %} 9 | async function test() { 10 | try { 11 | await Promise.reject(new Error('This is a test')); 12 | } catch (error: unknown) { 13 | console.error(error.message); 14 | } 15 | } 16 | 17 | test(); 18 | {% endcodeblock %} 19 | 20 | 21 | ### Fixed Code ✔️ 22 | 23 | If you set the `useUnknownInCatchVariables` option to `true` in your `tsconfig.json` file, you may encounter the **TS18046** error. 24 | 25 | Enabling the [useUnknownInCatchVariables](https://www.typescriptlang.org/tsconfig#useUnknownInCatchVariables) feature causes the error within a catch clause to be treated as the `unknown` type instead of `any`. As a result, you will need to incorporate a [type guard](/glossary/index.html#Type-Guards) or an [assertion function](/glossary/index.html#Assertion-Functions) to access properties on an object of type `unknown`: 26 | 27 | ```ts 28 | async function test() { 29 | try { 30 | await Promise.reject(new Error('This is a test')); 31 | } catch (error: unknown) { 32 | if (error instanceof Error) { 33 | console.error(error.message); 34 | } 35 | } 36 | } 37 | 38 | test(); 39 | ``` 40 | -------------------------------------------------------------------------------- /errors/includes/TS18xxx/TS18048.md: -------------------------------------------------------------------------------- 1 | ## TS18048 2 | 3 | > error TS18048: '`text`' is possibly '`undefined`'. 4 | 5 | ### Broken Code ❌ 6 | 7 | ```ts 8 | function getShortenedText(text?: string): string { 9 | return text.slice(0, 5); 10 | } 11 | ``` 12 | 13 | ### Fixed Code ✔️ 14 | 15 | If the `text` parameter is optional, it can potentially be of type `unknown`. When the type is `unknown`, accessing methods like [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) is not possible. 16 | 17 | To solve this error, we need to employ a [type guard](/glossary/index.html#Type-Guards) to ensure that `text` is of type `string`: 18 | 19 | ```ts 20 | function getShortenedText(text?: string): string { 21 | if (typeof text === 'string') { 22 | return text.slice(0, 5); 23 | } 24 | return ''; 25 | } 26 | ``` 27 | 28 | **Note:** We also need to employ a default return value to maintain the function return type of `string`. 29 | -------------------------------------------------------------------------------- /errors/includes/TS1xxx/TS1002.md: -------------------------------------------------------------------------------- 1 | ## TS1002 2 | 3 | > error TS1002: Unterminated string literal. 4 | 5 | ### Broken Code ❌ 6 | 7 | ```ts 8 | const text = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr 9 | ``` 10 | 11 | ### Fixed Code ✔️ 12 | 13 | You have to close the **string literal** with an ending `'`: 14 | 15 | ```ts 16 | const text = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr'; 17 | ``` 18 | 19 | If you want to support multiline text, then you would have to use **string concatenation**: 20 | 21 | ```ts 22 | const text = 23 | 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, ' + 24 | 'sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.'; 25 | ``` 26 | 27 | Another solution would be using a **[template literal](/glossary/index.html#Template-Literal)**: 28 | 29 | ```ts 30 | const text = `Lorem ipsum dolor sit amet, consetetur sadipscing elitr, 31 | sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.`; 32 | ``` 33 | -------------------------------------------------------------------------------- /errors/includes/TS1xxx/TS1005.md: -------------------------------------------------------------------------------- 1 | ## TS1005 2 | 3 | > error TS1005: '=' expected. 4 | 5 | ### Broken Code ❌ 6 | 7 | ```ts 8 | type Person { 9 | age: number; 10 | name: string; 11 | } 12 | ``` 13 | 14 | ### Fixed Code ✔️ 15 | 16 | You need to assign your type declaration using the `=` character: 17 | 18 | ```ts 19 | type Person = { 20 | age: number; 21 | name: string; 22 | }; 23 | ``` 24 | 25 | Alternatively you can declare an interface: 26 | 27 | ```ts 28 | interface Person { 29 | age: number; 30 | name: string; 31 | } 32 | ``` 33 | 34 | > error TS1005: ';' expected. 35 | 36 | ### Broken Code ❌ 37 | 38 | ```ts 39 | export function getNumbers(names: string[]) { 40 | return names.map(name => {[name]: parseInt(name)}); 41 | } 42 | ``` 43 | 44 | ### Fixed Code ✔️ 45 | 46 | When using an [**arrow function expression**](/glossary/index.html#Arrow-Function-Expression), you can implicitly return values by wrapping the [**object literal**](/glossary/index.html#Literal-Types) in parentheses: 47 | 48 | 49 | {% codeblock lang:ts mark:2 %} 50 | export function getNumbers(names: string[]) { 51 | return names.map(name => ({[name]: parseInt(name)})); 52 | } 53 | {% endcodeblock %} 54 | 55 | -------------------------------------------------------------------------------- /errors/includes/TS1xxx/TS1006.md: -------------------------------------------------------------------------------- 1 | ## TS1006 2 | 3 | > error TS1006: A file cannot have a reference to itself. 4 | 5 | ### Broken Code ❌ 6 | 7 | 8 | {% codeblock index.d.ts lang:ts %} 9 | ///