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