Skip to content

Improve types #87

@DavideViolante

Description

@DavideViolante
          I would recommend adding auto to the language unions, removing '3' as a possible engine and adopting this conditional structure in order to give the user a type error if they use a language that is not compatible with the used engine:
type CommonOcrSpaceLanguage =
  | 'chs' | 'cht' | 'dan' | 'dut' | 'eng'
  | 'fin' | 'fre' | 'ger' | 'ita'
  | 'jpn' | 'kor' | 'por' | 'rus'
  | 'spa' | 'slv' | 'swe' | 'ukr';

  type OcrSpaceLanguageEngine1 =
  | CommonOcrSpaceLanguage
  | 'ara' | 'bul' | 'hrv' | 'gre' | 'hun'
  | 'pol' | 'tur';

  type OcrSpaceLanguageEngine2 =
  | CommonOcrSpaceLanguage
  | 'nor' | 'tha' | 'vnm' | 'auto';

  type OcrSpaceFileTypes = string | 'PDF' | 'GIF' | 'PNG' | 'JPG' | 'TIF' | 'BMP';

  type BaseOcrSpaceOptions = {
    apiKey?: string;
    ocrUrl?: string;
    isOverlayRequired?: boolean;
    filetype?: OcrSpaceFileTypes;
    detectOrientation?: boolean;
    isCreateSearchablePdf?: boolean;
    isSearchablePdfHideTextLayer?: boolean;
    scale?: boolean;
    isTable?: boolean;
  }

  type OcrSpaceOptionsEngine1 = BaseOcrSpaceOptions &
    { OCREngine?: '1'; language?: OcrSpaceLanguageEngine1 };

  type OcrSpaceOptionsEngine2 = BaseOcrSpaceOptions &
    { OCREngine: '2'; language?: OcrSpaceLanguageEngine2 };

  export type OcrSpaceOptions = OcrSpaceOptionsEngine1 | OcrSpaceOptionsEngine2

Originally posted by @dreinon in #86 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions