From 8f91ed71aa622233725d56da98e5ca051e08321e Mon Sep 17 00:00:00 2001 From: Matt Pocock Date: Wed, 13 Sep 2023 10:17:13 +0100 Subject: [PATCH] 2023-09-13T09:17:13.105Z --- .../helpers.d.ts | 17 +++++++++++++++++ .../package.json | 8 ++++++++ .../src/index.ts | 5 +++++ .../tsconfig.json | 12 ++++++++++++ .../helpers.d.ts | 17 +++++++++++++++++ .../package.json | 8 ++++++++ .../src/index.ts | 5 +++++ .../tsconfig.json | 13 +++++++++++++ .../192-tsconfig-bases.explainer.ts | 2 ++ 9 files changed, 87 insertions(+) create mode 100644 src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/helpers.d.ts create mode 100644 src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/package.json create mode 100644 src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/src/index.ts create mode 100644 src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/tsconfig.json create mode 100644 src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/helpers.d.ts create mode 100644 src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/package.json create mode 100644 src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/src/index.ts create mode 100644 src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/tsconfig.json diff --git a/src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/helpers.d.ts b/src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/helpers.d.ts new file mode 100644 index 0000000..3ae28b9 --- /dev/null +++ b/src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/helpers.d.ts @@ -0,0 +1,17 @@ +type Expect = T; +type Equal = (() => T extends X ? 1 : 2) extends () => T extends Y + ? 1 + : 2 + ? true + : false; + +/** + * Checks that Y is assignable to X. + * + * For instance, `Extends` 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 = Y extends X ? true : false; diff --git a/src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/package.json b/src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/package.json new file mode 100644 index 0000000..e11b297 --- /dev/null +++ b/src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/package.json @@ -0,0 +1,8 @@ +{ + "name": "exercise", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "dev": "tsc --watch" + } +} diff --git a/src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/src/index.ts b/src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/src/index.ts new file mode 100644 index 0000000..231da65 --- /dev/null +++ b/src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/src/index.ts @@ -0,0 +1,5 @@ +const array = [1, 2, 3]; + +const mightNotExist = array[3]; + +type test = Expect>; diff --git a/src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/tsconfig.json b/src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/tsconfig.json new file mode 100644 index 0000000..4627a58 --- /dev/null +++ b/src/080-configuring-typescript/191-no-unchecked-indexed-access.problem/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ESNext", + "moduleResolution": "Bundler", + "esModuleInterop": true, + "noEmit": true, + "strict": true, + "skipLibCheck": true, + "isolatedModules": true, + }, +} \ No newline at end of file diff --git a/src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/helpers.d.ts b/src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/helpers.d.ts new file mode 100644 index 0000000..3ae28b9 --- /dev/null +++ b/src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/helpers.d.ts @@ -0,0 +1,17 @@ +type Expect = T; +type Equal = (() => T extends X ? 1 : 2) extends () => T extends Y + ? 1 + : 2 + ? true + : false; + +/** + * Checks that Y is assignable to X. + * + * For instance, `Extends` 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 = Y extends X ? true : false; diff --git a/src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/package.json b/src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/package.json new file mode 100644 index 0000000..e11b297 --- /dev/null +++ b/src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/package.json @@ -0,0 +1,8 @@ +{ + "name": "exercise", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "dev": "tsc --watch" + } +} diff --git a/src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/src/index.ts b/src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/src/index.ts new file mode 100644 index 0000000..231da65 --- /dev/null +++ b/src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/src/index.ts @@ -0,0 +1,5 @@ +const array = [1, 2, 3]; + +const mightNotExist = array[3]; + +type test = Expect>; diff --git a/src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/tsconfig.json b/src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/tsconfig.json new file mode 100644 index 0000000..dfb60b4 --- /dev/null +++ b/src/080-configuring-typescript/191-no-unchecked-indexed-access.solution/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ESNext", + "moduleResolution": "Bundler", + "esModuleInterop": true, + "noEmit": true, + "strict": true, + "skipLibCheck": true, + "isolatedModules": true, + "noUncheckedIndexedAccess": true + }, +} \ No newline at end of file diff --git a/src/080-configuring-typescript/192-tsconfig-bases.explainer.ts b/src/080-configuring-typescript/192-tsconfig-bases.explainer.ts index ec728ab..e638fb6 100644 --- a/src/080-configuring-typescript/192-tsconfig-bases.explainer.ts +++ b/src/080-configuring-typescript/192-tsconfig-bases.explainer.ts @@ -1 +1,3 @@ // https://github.com/tsconfig/bases + +// Note that strictest is not what I recommend