-
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
de2803b
commit 9dc135e
Showing
12 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
17 changes: 17 additions & 0 deletions
17
src/065-types-you-dont-control/174-definitely-typed.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; |
12 changes: 12 additions & 0 deletions
12
src/065-types-you-dont-control/174-definitely-typed.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,12 @@ | ||
{ | ||
"name": "exercise", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "tsc --watch" | ||
}, | ||
"dependencies": { | ||
"diff": "^5.1.0" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/065-types-you-dont-control/174-definitely-typed.problem/pnpm-lock.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
src/065-types-you-dont-control/174-definitely-typed.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,19 @@ | ||
import Diff from "diff"; | ||
|
||
const message = "Hello, world!"; | ||
|
||
const secondMessage = "Goodbye, world!"; | ||
|
||
const diff = Diff.diffChars(message, secondMessage); | ||
|
||
type test = Expect< | ||
Equal< | ||
typeof diff, | ||
{ | ||
count?: number; | ||
value: string; | ||
added?: boolean; | ||
removed?: boolean; | ||
}[] | ||
> | ||
>; |
15 changes: 15 additions & 0 deletions
15
src/065-types-you-dont-control/174-definitely-typed.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,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"esModuleInterop": true, | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"isolatedModules": true, | ||
"moduleDetection": "force", | ||
"verbatimModuleSyntax": true | ||
}, | ||
} |
Empty file.
17 changes: 17 additions & 0 deletions
17
src/065-types-you-dont-control/174-definitely-typed.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; |
15 changes: 15 additions & 0 deletions
15
src/065-types-you-dont-control/174-definitely-typed.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,15 @@ | ||
{ | ||
"name": "exercise", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "tsc --watch" | ||
}, | ||
"dependencies": { | ||
"diff": "^5.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/diff": "^5.0.4" | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/065-types-you-dont-control/174-definitely-typed.solution/pnpm-lock.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
src/065-types-you-dont-control/174-definitely-typed.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,19 @@ | ||
import Diff from "diff"; | ||
|
||
const message = "Hello, world!"; | ||
|
||
const secondMessage = "Goodbye, world!"; | ||
|
||
const diff = Diff.diffChars(message, secondMessage); | ||
|
||
type test = Expect< | ||
Equal< | ||
typeof diff, | ||
{ | ||
count?: number; | ||
value: string; | ||
added?: boolean; | ||
removed?: boolean; | ||
}[] | ||
> | ||
>; |
15 changes: 15 additions & 0 deletions
15
src/065-types-you-dont-control/174-definitely-typed.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,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"esModuleInterop": true, | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"isolatedModules": true, | ||
"moduleDetection": "force", | ||
"verbatimModuleSyntax": true | ||
}, | ||
} |