react-scorm-provider icon indicating copy to clipboard operation
react-scorm-provider copied to clipboard

TypeScript typings

Open wojtekmaj opened this issue 2 years ago • 2 comments

Since I had to write these anyway, I'm sharing TypeScript typings for this package in case somebody needs them. It would be also a neat base for potential TypeScript migration in the future.

declare module 'react-scorm-provider' {
  type ScormVersion = '1.2' | '2004';

  type SuspendData = Record<string, unknown>;

  type Status =
    | 'passed'
    | 'completed'
    | 'failed'
    | 'incomplete'
    | 'browsed'
    | 'not attempted'
    | 'unknown';

  type ScoreObj = {
    value: number;
    min: number;
    max: number;
    status: string;
  };

  export type ScoProp = {
    apiConnected: boolean;
    clearSuspendData: () => SuspendData;
    completionStatus: Status;
    get: (param: string) => unknown;
    getSuspendData: () => SuspendData;
    learnerName: string;
    scormVersion: ScormVersion;
    set: (param: string, val: any, deferSaveCall?: boolean) => void;
    setScore: (scoreObj: ScoreObj) => any[];
    setStatus: (status: Status, deferSaveCall?: boolean) => void;
    setSuspendData: (key: string | number, val: any) => SuspendData;
    suspendData: SuspendData;
  };

  const ScormProvider: React.ComponentType<{
    children?: React.ReactNode;
    version?: ScormVersion;
    debug?: boolean;
  }>;

  export const withScorm: () => <P extends object>(
    Component: React.ComponentType<P>,
  ) => React.ComponentType<Omit<P, 'sco'>>;

  export default ScormProvider;
}

wojtekmaj avatar Jun 23 '23 13:06 wojtekmaj

Thanks for doing this. I've been meaning to update this entire project to hooks and typescript and remove the dependency on the old pipwerks SCORM API wrapper. But there's just never time...

JayV30 avatar Jul 10 '23 23:07 JayV30

Leaving this as an open issue for visibility.

JayV30 avatar Jul 10 '23 23:07 JayV30