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

Improve type narrowing and error handling #1073

Merged
merged 10 commits into from
Nov 19, 2024
Merged

Commits on Nov 19, 2024

  1. Handle internal errors

    Add a custom error class for errors that aren't user error and can be
    considered a bug in the code.
    
    For now I've scoped this to ListResources, but a similar approach can be
    adopted for other components too.
    victorlin committed Nov 19, 2024
    Configuration menu
    Copy the full SHA
    84470e4 View commit details
    Browse the repository at this point in the history
  2. Condition on versioned value

    Instead of indirectly inferring this from presence of a lastUpdated
    value for the first group.
    victorlin committed Nov 19, 2024
    Configuration menu
    Copy the full SHA
    c175886 View commit details
    Browse the repository at this point in the history
  3. Update Group prop types

    This better reflects the actual usage.
    victorlin committed Nov 19, 2024
    Configuration menu
    Copy the full SHA
    9fab60d View commit details
    Browse the repository at this point in the history
  4. Add type for versioned group

    This reduces the amount of optional properties and need for scattered
    type narrowing downstream.
    
    Some restructuring of the code was necessary for proper type narrowing.
    This includes changing the switch/case to if/else which allows
    redefining variables with the same name in each block.
    victorlin committed Nov 19, 2024
    Configuration menu
    Copy the full SHA
    c1096d4 View commit details
    Browse the repository at this point in the history
  5. Add type for versioned resource

    This reduces the amount of optional properties and need for scattered
    type narrowing downstream.
    victorlin committed Nov 19, 2024
    Configuration menu
    Copy the full SHA
    950c70f View commit details
    Browse the repository at this point in the history
  6. Replace displayName null check with conditional type

    With the current code, it is not possible for displayName to be unset in
    getMaxResourceWidth. Make this clear with type narrowing.
    victorlin committed Nov 19, 2024
    Configuration menu
    Copy the full SHA
    52c2919 View commit details
    Browse the repository at this point in the history
  7. Use narrowing instead of non-null assertion

    Same behavior but using better practices.
    victorlin committed Nov 19, 2024
    Configuration menu
    Copy the full SHA
    cd02127 View commit details
    Browse the repository at this point in the history
  8. Properly check that flatData[0] is defined

    The previous check was loosely coupled, relying on a non-null assertion.
    This should be more clear to both the compiler and humans.
    victorlin committed Nov 19, 2024
    Configuration menu
    Copy the full SHA
    7aaeb48 View commit details
    Browse the repository at this point in the history
  9. _setDisplayName: Replace optional chaining with proper error handing

    With the current code, it is not possible for resources[i-1] to be
    undefined. Make this clear with type narrowing.
    victorlin committed Nov 19, 2024
    Configuration menu
    Copy the full SHA
    14e0e82 View commit details
    Browse the repository at this point in the history
  10. Throw an error if IndividualResource cannot be rendered

    With the current code, this condition will always fail. Prevent this
    from silently passing and instead raise an error.
    victorlin committed Nov 19, 2024
    Configuration menu
    Copy the full SHA
    f8feb3e View commit details
    Browse the repository at this point in the history