Uploaded image for project: 'OpenShift Bugs'
  1. OpenShift Bugs
  2. OCPBUGS-31099

incorrect return type for useK8sWatchResource

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Undefined Undefined
    • None
    • 4.15
    • Management Console
    • None
    • Quality / Stability / Reliability
    • False
    • Hide

      None

      Show
      None
    • None
    • Low
    • No
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      `useK8sWatchResource` return type is incorrect.

       

      export const useK8sWatchResource = <R extends K8sResourceCommon | K8sResourceCommon[]>(
        initResource: WatchK8sResource | null,
        initModel?: K8sModelCommon,
        options?: Partial<WebSocketOptions & RequestInit & { wsPrefix?: string; pathPrefix?: string }>,
      ): WatchK8sResult<R> => {
      
      export type WatchK8sResult<R extends K8sResourceCommon | K8sResourceCommon[]> = [
        data: R,
        loaded: boolean,
        loadError: unknown,
      ]; 

      `WatchK8sResult['data']` is of type `R`. However, the value of data may be `undefined` at times.

       

      The affect of this is null checks may be missed. Or if eslint rules are in place may inform the dev that a correctly placed null check is unnecessary because the type can never be undefined.

      The type for `useK8sWatchResource` should be updated to account for data possibly being `undefined`. This change needs to be applied in the dynamic-plugin-sdk.

      cc vszocs@redhat.com 

              vszocs@redhat.com Vojtech Szocs
              christianvogt Christian Vogt
              None
              None
              YaDan Pei YaDan Pei
              None
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: