Skip to content

Commit

Permalink
2023-09-12T14:15:51.834Z
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock committed Sep 12, 2023
1 parent 963ed14 commit dba8d1b
Show file tree
Hide file tree
Showing 56 changed files with 441 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,11 @@
{
"name": "117-const-enums.explainer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "tsc --watch"
},
"keywords": [],
"author": "Matt Pocock"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const state = DEBUG.getState();

type test = Expect<Equal<typeof state, { id: string }>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es2020",
"module": "ESNext",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"declaration": true,
"skipLibCheck": true,
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"moduleDetection": "force"
},
}
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,11 @@
{
"name": "117-const-enums.explainer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "tsc --watch"
},
"keywords": [],
"author": "Matt Pocock"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare const DEBUG: {
getState(): { id: string };
};

const state = DEBUG.getState();

type test = Expect<Equal<typeof state, { id: string }>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es2020",
"module": "ESNext",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"declaration": true,
"skipLibCheck": true,
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"moduleDetection": "force"
},
}
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,11 @@
{
"name": "117-const-enums.explainer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "tsc --watch"
},
"keywords": [],
"author": "Matt Pocock"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare const DEBUG: {
getState(): { id: string };
};

const state = DEBUG.getState();

type test = Expect<Equal<typeof state, { id: string }>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const state = DEBUG.getState();

type test = Expect<Equal<typeof state, { id: string }>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es2020",
"module": "ESNext",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"declaration": true,
"skipLibCheck": true,
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"moduleDetection": "force"
},
}
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,11 @@
{
"name": "117-const-enums.explainer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "tsc --watch"
},
"keywords": [],
"author": "Matt Pocock"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare global {
const DEBUG: {
getState(): { id: string };
};
}

const state = DEBUG.getState();

type test = Expect<Equal<typeof state, { id: string }>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const state = DEBUG.getState();

type test = Expect<Equal<typeof state, { id: string }>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es2020",
"module": "ESNext",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"declaration": true,
"skipLibCheck": true,
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"moduleDetection": "force"
},
}
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,11 @@
{
"name": "117-const-enums.explainer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "tsc --watch"
},
"keywords": [],
"author": "Matt Pocock"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const DEBUG: {
getState(): { id: string };
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const state = DEBUG.getState();

type test = Expect<Equal<typeof state, { id: string }>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const state = DEBUG.getState();

type test = Expect<Equal<typeof state, { id: string }>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es2020",
"module": "ESNext",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"declaration": true,
"skipLibCheck": true,
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"moduleDetection": "force"
},
}
Empty file.
Empty file.
Empty file.
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,11 @@
{
"name": "117-const-enums.explainer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "tsc --watch"
},
"keywords": [],
"author": "Matt Pocock"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const state = window.DEBUG.getState();

type test = Expect<Equal<typeof state, { id: string }>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es2020",
"module": "ESNext",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"declaration": true,
"skipLibCheck": true,
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"moduleDetection": "force"
},
}
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,11 @@
{
"name": "117-const-enums.explainer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "tsc --watch"
},
"keywords": [],
"author": "Matt Pocock"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const state = window.DEBUG.getState();

type test = Expect<Equal<typeof state, { id: string }>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Window {
DEBUG: {
getState(): { id: string };
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es2020",
"module": "ESNext",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"declaration": true,
"skipLibCheck": true,
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"moduleDetection": "force"
},
}
Empty file.
Empty file.
Empty file.
Loading

0 comments on commit dba8d1b

Please sign in to comment.