Skip to content

Commit

Permalink
2023-09-19T09:52:58.562Z
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock committed Sep 19, 2023
1 parent de2803b commit 9dc135e
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 0 deletions.
Empty file.
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;
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"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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;
}[]
>
>;
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.
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;
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"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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;
}[]
>
>;
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
},
}

0 comments on commit 9dc135e

Please sign in to comment.