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

chore: fix remaining strictNullChecks errors; enforce in tsconfig #758

Merged
merged 12 commits into from
Nov 9, 2020
Merged

chore: fix remaining strictNullChecks errors; enforce in tsconfig #758

merged 12 commits into from
Nov 9, 2020

Conversation

dorianj
Copy link
Contributor

@dorianj dorianj commented Nov 7, 2020

Summary of Changes

Fix all remaining strictNullChecks violations. Remove it from betterer and add to tsconfig.json. Once this lands, I'll @channel in front-end that their PRs must be rebased, else there's possibility of merge violations on master.

There's still mostly easy fixes (in particular, 3 or 4 things missed in earlier PRs), but also some trickier ones. I've given more details about the trickier changes in the commit messages.

There should be no functional changes, and I've tried to do these in as low-risk a way as possible. Rather than get the "perfect" types in place, I've generally opted to try to just document what's in place. A class of this is places where some properties "should" be optional but currently are mandatory, and therefore require a lot of placeholder objects get passed down (a specific example of this is having to pass down a ResourceType.table inside a SearchType.CLEAR_TERM object)

But overall I feel like this should be fairly safe, but would appreciate a somewhat close eye.

Tests

I added one test for some added parsing, but mostly this didn't create new behaviors or branches, so no other new tests.

Documentation

n/a

CheckList

Make sure you have checked all steps below to ensure a timely review.

  • PR title addresses the issue accurately and concisely. Example: "Updates the version of Flask to v1.0.2"
  • PR includes a summary of changes, including screenshots of any UI changes.
  • PR adds unit tests, updates existing unit tests, OR documents why no test additions or modifications are needed.
  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public python functions and the classes in the PR contain docstrings that explain what it does
  • PR passes all tests documented in the developer guide

Previously these two keys were inconsistently treated as being
nullable, undefined, or required. Make them optional (undefined) everywhere,
which seems to be author's intent.

Also add a simple test to exercise the malformed handling, since that's now
explicitly possible.

Signed-off-by: Dorian Johnson <[email protected]>
The convention seems to be that statusCode is null when isLoading is true,
and assignments are already happening that way, so just update the typings
to reflect that.

Signed-off-by: Dorian Johnson <[email protected]>
First, getFilterConfigByResource is expected to sometimes return undefined,
so mark the signature as such. This fixes a test which mocked out an undefined
return value. TBH I'm not sure how the original implmentation passed the type
checker, I think there's an `any` in the chain that defeated it.

Second, in the call to `connect`, don't specify null for optional props, it
confuses the typechecker. Instead just omit them.

Signed-off-by: Dorian Johnson <[email protected]>
Build the return via map, not via forEach / push, removes LOC and obviates
needing to explictly type it.

Also add the any type to the call signature. Previously this was implied due to
the opaque type of the return array builder. But as the nearby TODO indicates,
the callsites freak out when they learn the return type is
`Promise<AxiosResponse<any> | undefined>>[]`, and I don't want to dig deeper
into that.

Signed-off-by: Dorian Johnson <[email protected]>
Also introduce an annoying workaround to achieve the null action prop

Signed-off-by: Dorian Johnson <[email protected]>
These types are pretty unhelpful, in that there are a bunch of keys that
aren't actually used for certain search types, and are thus ignored in most
practices. This one is no different than the others, so just specify a random
default.

I'm not 100% certain in this change, but I can't find anywhere that branches
on searchType being null, so I think it's safe.

Signed-off-by: Dorian Johnson <[email protected]>
These tests dig deep into the config tree and pull out specific combinations
of keys from dicts the author "knows" exist. That's fine, but it does not
please the type checker.

Instead, blackhole the reference into <any> and add a runtime defininition
check, that way if the config structure changes it'll be flagged as a test
failure.

Signed-off-by: Dorian Johnson <[email protected]>
Copy link
Member

@Golodhros Golodhros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome, thanks a lot @dorianj !!

LGTM

@dorianj
Copy link
Contributor Author

dorianj commented Nov 9, 2020

Great @Golodhros, can you merge please? Thanks for the review

@Golodhros
Copy link
Member

Great @Golodhros, can you merge please? Thanks for the review

Yeah, I will merge tomorrow, I want to give some time to others to check it out just in case!

@Golodhros Golodhros merged commit d27326f into amundsen-io:master Nov 9, 2020
@dorianj dorianj deleted the dj-typings-final branch November 10, 2020 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants