-
Notifications
You must be signed in to change notification settings - Fork 129
chore!: enable noUncheckedIndexedAccess
#2006
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
chore!: enable noUncheckedIndexedAccess
#2006
Conversation
|
@markov00 Before I fix all the errors from this change, I wanted to get your take on this change? I have run into this more and more and I feel not enabling this makes the type checking very loose. ExampleA great example of this is fetching a single elastic-charts/packages/charts/src/state/utils.ts Lines 21 to 33 in 16ce203
Currently if we call this function like... const spec: HeatmapSpec = getSpecFromStore<HeatmapSpec>(specs, ChartType.Heatmap, SpecType.Series);Typescript does NOT throw any errors and is completely fine with spec being The downsides I see to this are...
|
|
@nickofthyme I totally agree with these changes, I see the benefit and I think is desirable, go on with it please |
- getSpecFromStore option to require spec or throw - getSpecFromStore option to optionally get spec or null
Newer versions of typescript/vscode now support multiple tsconfig.json files in a single project. Previously the base tsconfig.json was the only file used and all others were ignored. Now if a tsconfig.json file is at the root of a directory that will be applied to all child directories. This change was causing failures in cli but not is vscode for test files.
This index access makes it easier to type and describe the different variants This is required as a limitation of typescript/vscode not permitting nested tsconfigs
here we favor the use of forced unwrapping (i.e. `d[0]!`) for less strict checking
here we favor the use of forced unwrapping (i.e. `d[0]!`) for less strict checking
markov00
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just code review (I skipped the changes in Storybook because it looks relatively safe).
packages/charts/src/chart_types/heatmap/renderer/canvas/canvas_renderers.ts
Show resolved
Hide resolved
packages/charts/src/chart_types/partition_chart/state/selectors/get_debug_state.test.ts
Show resolved
Hide resolved
packages/charts/src/chart_types/xy_chart/axes/timeslip/chrono/cached_chrono.ts
Show resolved
Hide resolved
Co-authored-by: Marco Vettorello <vettorello.marco@gmail.com>
markov00
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to merge when CI is green.
One thing: for safety reasons what if we merge this as a breaking change and generate a release just before merging this? it could be easy to track/rollback in case of failures
… enable-no-unchecked-access
noUncheckedIndexedAccessnoUncheckedIndexedAccess
enables stricter types for array access. BREAKING CHANGE: Enables stricter type option in src and could have unexpected changes. This release is meant to serve as a clean break in case any issues arise. --------- Co-authored-by: Marco Vettorello <vettorello.marco@gmail.com>
## [56.0.1](v56.0.0...v56.0.1) (2023-04-18) ### Code Refactoring * enable `noUncheckedIndexedAccess` ([#2006](#2006)) ([2f70349](2f70349)) ### BREAKING CHANGES * Enables stricter type option in src and could have unexpected changes. This release is meant to serve as a clean break in case any issues arise.
enables stricter types for array access. BREAKING CHANGE: Enables stricter type option in src and could have unexpected changes. This release is meant to serve as a clean break in case any issues arise.
## [56.0.1](v56.0.0...v56.0.1) (2023-04-19) ### Code Refactoring * enable `noUncheckedIndexedAccess` ([#2006](#2006)) ([f446cca](f446cca)) ### BREAKING CHANGES * Enables stricter type option in src and could have unexpected changes. This release is meant to serve as a clean break in case any issues arise.
# [57.0.0](v56.0.0...v57.0.0) (2023-04-19) ### Code Refactoring * enable `noUncheckedIndexedAccess` ([#2006](#2006)) ([f446cca](f446cca)) ### BREAKING CHANGES * Enables stricter type option in src and could have unexpected changes. This release is meant to serve as a clean break in case any issues arise.
Summary
Enables
noUncheckedIndexedAccessacross all code.Details
Enabling the Typescript
strictmode does not check for array index access (microsoft/TypeScript#39560) and assumes assessing a value at an array index produces the array/tuple type. However this can be deceiving and lead to errors in the code if this array access returnsundefined.Enabling this across the
/srccreates a consistent and more accurate type checking. This does require a bit more type guards to ensure the value is defined.Note on
tsconfig.jsonstructuresSo typescript/VScode changed how they respect nested
tsconfig.jsonfiles. In the past, VScode would only look to the top-leveltsconfig.jsonand ignore all other named-varients (i.e.tsconfig.lint.json) or nestedtsconfig.jsonfiles (i.e.storybook/tsconfig.json).Now this has changed, to where VScode will apply type checking using the nearest parent directory containing a
tsconfig.jsonfile. But the bad thing about this is that this assumes thattsconfig.jsonincludes all child directories which may not be and often is not true! Thus making type checking a much bigger pain for it to be consistent between the IDE plugins and thetsccli checks.Ideally, we could apply certain
compilerOptionsto different directories and/or files much like eslint, because enablingnoUncheckedIndexedAccessin test files is unnecessary and a little annoying.To further complicate things, even if this did work, typescript automatically includes transitive imports thus requiring type checking on src code using different
compilerOptionsleading to conflicting linting errors like...So with that said, the best solution is just to apply the same
compilerOptionsthroughout the code and avoid nested overly-constrainedtsconfig.jsonfiles, in favor oftsconfig.<something>.json.The next idea is to allow forced unwrapping array access (i.e.
someThing[0]!.someProperty) everywhere except/src. But there are no linting rules to enforce this, the only semi-related rule is@typescript-eslint/no-unnecessary-type-assertionIssues
close #1757
Checklist
:xy,:partition)closes #123,fixes #123)packages/charts/src/index.ts