-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c62786b
commit 8f91ed7
Showing
9 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/helpers.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
type Expect<T extends true> = T; | ||
type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y | ||
? 1 | ||
: 2 | ||
? true | ||
: false; | ||
|
||
/** | ||
* Checks that Y is assignable to X. | ||
* | ||
* For instance, `Extends<string, 'a'>` is true. This is because | ||
* 'a' can be passed to a function which expects a string. | ||
* | ||
* But `Extends<'a', string>` is false. This is because a string | ||
* CANNOT be passed to a function which expects 'a'. | ||
*/ | ||
type Extends<X, Y> = Y extends X ? true : false; |
8 changes: 8 additions & 0 deletions
8
src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "exercise", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"dev": "tsc --watch" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const array = [1, 2, 3]; | ||
|
||
const mightNotExist = array[3]; | ||
|
||
type test = Expect<Equal<typeof mightNotExist, number | undefined>>; |
12 changes: 12 additions & 0 deletions
12
src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"module": "ESNext", | ||
"moduleResolution": "Bundler", | ||
"esModuleInterop": true, | ||
"noEmit": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"isolatedModules": true, | ||
}, | ||
} |
17 changes: 17 additions & 0 deletions
17
src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/helpers.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
type Expect<T extends true> = T; | ||
type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y | ||
? 1 | ||
: 2 | ||
? true | ||
: false; | ||
|
||
/** | ||
* Checks that Y is assignable to X. | ||
* | ||
* For instance, `Extends<string, 'a'>` is true. This is because | ||
* 'a' can be passed to a function which expects a string. | ||
* | ||
* But `Extends<'a', string>` is false. This is because a string | ||
* CANNOT be passed to a function which expects 'a'. | ||
*/ | ||
type Extends<X, Y> = Y extends X ? true : false; |
8 changes: 8 additions & 0 deletions
8
src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "exercise", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"dev": "tsc --watch" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const array = [1, 2, 3]; | ||
|
||
const mightNotExist = array[3]; | ||
|
||
type test = Expect<Equal<typeof mightNotExist, number | undefined>>; |
13 changes: 13 additions & 0 deletions
13
src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"module": "ESNext", | ||
"moduleResolution": "Bundler", | ||
"esModuleInterop": true, | ||
"noEmit": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"isolatedModules": true, | ||
"noUncheckedIndexedAccess": true | ||
}, | ||
} |
2 changes: 2 additions & 0 deletions
2
src/080-configuring-typescript/192-tsconfig-bases.explainer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
// https://github.com/tsconfig/bases | ||
|
||
// Note that strictest is not what I recommend |