S4-NetQuest / react-scorm-provider

Components to easily enable SCORM API communication in React projects.
MIT License
61 stars 19 forks source link

TypeScript typings #44

Open wojtekmaj opened 1 year ago

wojtekmaj commented 1 year ago

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;
}
JayV30 commented 1 year ago

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 commented 1 year ago

Leaving this as an open issue for visibility.