Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding noUncheckedIndexedAccess to tsconfig #6009

Closed
dylangrandmont opened this issue Mar 10, 2023 · 2 comments
Closed

Consider adding noUncheckedIndexedAccess to tsconfig #6009

dylangrandmont opened this issue Mar 10, 2023 · 2 comments

Comments

@dylangrandmont
Copy link
Contributor

Environment

  • Package version(s): 4.x and 5.x
  • Browser and OS versions: (Applied to all, and to TypeScript >= 4.1)

Feature request

The request is for blueprint to include "noUncheckedIndexedAccess": true in its tsconfig. The reasoning is as follows:

By default, TypeScript will not correctly infer when an array element can be undefined

  let g: Array<number> = []
  let h = g[0] // type of h is number

On ~recent release of TS (4.1) this behaviour can be changed via a configuration
microsoft/TypeScript#39560
https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess

Unfortunately because blueprint ships tsx files directly, any library which uses blueprint as a dependency will be unable to set "noUncheckedIndexedAccess": true in its tsconfig.ts. Doing so will result in build time failures during the TypeScript compilation, for example

./node_modules/@blueprintjs/core/src/components/tree/tree.tsx:98:31
Type error: Type 'undefined' cannot be used as an index t
info  - Linting and checking validity of types .Failed to compile.

./node_modules/@blueprintjs/core/src/components/tree/tree.tsx:98:31
Type error: Type 'undefined' cannot be used as an index type.

     ): TreeNodeInfo<U> {
         if (path.length === 1) {
             return treeNodes![path[0]];
                               ^
         } else {
             return Tree.nodeFromPath(path.slice(1), treeNodes![path[0]].childNodes);
         }

@adidahiya
Copy link
Contributor

adidahiya commented Mar 13, 2023

Unfortunately because blueprint ships tsx files directly

You shouldn't be pulling these files into your TS compilation pipeline. They are only there to provide accurate sourcemaps. Your tsc should only see (be given access to) the .d.ts files.

@dylangrandmont
Copy link
Contributor Author

You shouldn't be pulling these files into your TS compilation pipeline. They are only there to provide accurate sourcemaps. Your tsc should only see (be given access to) the .d.ts files.

Thanks for the reply @adidahiya. I see I am inadvertently importing some types from @blueprintjs/core/src/components and this is my underlying issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants