1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-21 18:02:35 +01:00

improve types

This commit is contained in:
Mikael Finstad 2024-08-27 21:03:27 +02:00
parent 13485fa686
commit 8eef3cbc16
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26
7 changed files with 34 additions and 15 deletions

View File

@ -55,6 +55,7 @@
"@types/lodash": "^4.14.202",
"@types/lodash.debounce": "^4",
"@types/luxon": "^3.4.2",
"@types/mime-types": "^2.1.4",
"@types/morgan": "^1.9.9",
"@types/node": "18",
"@types/react": "^18.2.66",

View File

@ -1687,7 +1687,7 @@ function App() {
// first check if it is a single directory, and if so, read it recursively
if (filePaths.length === 1) {
const firstFilePath = filePaths[0];
const firstFilePath = filePaths[0]!;
const firstFileStat = await lstat(firstFilePath);
if (firstFileStat.isDirectory()) {
console.log('Reading directory...');

View File

@ -1,6 +1,5 @@
import JSON5 from 'json5';
import i18n from 'i18next';
import type { parse as CueParse } from 'cue-parser';
import invariant from 'tiny-invariant';
import { parseSrtToSegments, formatSrt, parseCuesheet, parseXmeml, parseFcpXml, parseCsv, parseCutlist, parsePbf, parseMplayerEdl, formatCsvHuman, formatTsv, formatCsvFrames, formatCsvSeconds, parseCsvTime, getFrameValParser, parseDvAnalyzerSummaryTxt } from './edlFormats';
@ -9,7 +8,7 @@ import { getOutPath } from './util';
import { EdlExportType, EdlFileType, EdlImportType, Segment, StateSegment } from './types';
const { readFile, writeFile } = window.require('fs/promises');
const cueParser: { parse: typeof CueParse } = window.require('cue-parser');
const cueParser = window.require('cue-parser');
const { basename } = window.require('path');
const { dialog } = window.require('@electron/remote');
@ -85,7 +84,7 @@ export async function saveLlcProject({ savePath, filePath, cutSegments }) {
}
export async function loadLlcProject(path: string) {
const parsed = JSON5.parse(await readFile(path)) as unknown;
const parsed = JSON5.parse(await readFile(path) as unknown as string) as unknown;
if (parsed == null || typeof parsed !== 'object') throw new Error('Invalid LLC file');
let mediaFileName: string | undefined;
if ('mediaFileName' in parsed && typeof parsed.mediaFileName === 'string') {

View File

@ -1,7 +1,6 @@
import dataUriToBuffer from 'data-uri-to-buffer';
import pMap from 'p-map';
import { useCallback } from 'react';
import type * as FsPromises from 'node:fs/promises';
import { getSuffixedOutPath, getOutDir, transferTimestamps, getSuffixedFileName, getOutPath, escapeRegExp, fsOperationWithRetry } from '../util';
import { getNumDigits } from '../segments';
@ -11,7 +10,7 @@ import { FormatTimecode } from '../types';
import { CaptureFormat } from '../../../../types';
const mime = window.require('mime-types');
const { rename, readdir, writeFile }: typeof FsPromises = window.require('fs/promises');
const { rename, readdir, writeFile } = window.require('fs/promises');
function getFrameFromVideo(video: HTMLVideoElement, format: CaptureFormat, quality: number) {

View File

@ -5,6 +5,12 @@ import { enableMapSet } from 'immer';
import * as Electron from 'electron';
import Remote from '@electron/remote';
import type path from 'node:path';
import type fsPromises from 'node:fs/promises';
import type fsExtraRaw from 'fs-extra';
import type mimeTypes from 'mime-types';
import type i18nextFsBackend from 'i18next-fs-backend';
import type fileType from 'file-type';
import type cueParser from 'cue-parser';
import '@fontsource/open-sans/300.css';
import '@fontsource/open-sans/300-italic.css';
@ -29,6 +35,9 @@ import './main.css';
import './swal2.scss';
// something wrong with the tyep
type FsExtra = typeof fsExtraRaw & { exists: (p: string) => Promise<boolean> };
type TypedRemote = Omit<typeof Remote, 'require'> & {
require: <T extends string>(module: T) => (
T extends './index.js' ? typeof main :
@ -43,9 +52,15 @@ declare global {
T extends '@electron/remote' ? TypedRemote :
T extends 'electron' ? typeof Electron :
T extends 'path' ? typeof path :
// todo more
// eslint-disable-next-line @typescript-eslint/no-explicit-any
any
T extends 'node:path' ? typeof path :
T extends 'fs/promises' ? typeof fsPromises :
T extends 'node:fs/promises' ? typeof fsPromises :
T extends 'fs-extra' ? FsExtra :
T extends 'mime-types' ? typeof mimeTypes :
T extends 'i18next-fs-backend' ? typeof i18nextFsBackend :
T extends 'file-type' ? typeof fileType :
T extends 'cue-parser' ? typeof cueParser :
never
);
}
}

View File

@ -5,18 +5,15 @@ import prettyBytes from 'pretty-bytes';
import sortBy from 'lodash/sortBy';
import pRetry, { Options } from 'p-retry';
import { ExecaError } from 'execa';
import type * as FsPromises from 'node:fs/promises';
import type * as FsExtra from 'fs-extra';
import type { PlatformPath } from 'node:path';
import isDev from './isDev';
import Swal, { errorToast, toast } from './swal';
import { ffmpegExtractWindow } from './util/constants';
import { appName } from '../../main/common';
const { dirname, parse: parsePath, join, extname, isAbsolute, resolve, basename }: PlatformPath = window.require('path');
const fsExtra: typeof FsExtra = window.require('fs-extra');
const { stat, lstat, readdir, utimes, unlink }: typeof FsPromises = window.require('fs/promises');
const { dirname, parse: parsePath, join, extname, isAbsolute, resolve, basename } = window.require('path');
const fsExtra = window.require('fs-extra');
const { stat, lstat, readdir, utimes, unlink } = window.require('fs/promises');
const { ipcRenderer } = window.require('electron');
const remote = window.require('@electron/remote');
const { isWindows, isMac } = remote.require('./index.js');

View File

@ -2089,6 +2089,13 @@ __metadata:
languageName: node
linkType: hard
"@types/mime-types@npm:^2.1.4":
version: 2.1.4
resolution: "@types/mime-types@npm:2.1.4"
checksum: 10/f8c521c54ee0c0b9f90a65356a80b1413ed27ccdc94f5c7ebb3de5d63cedb559cd2610ea55b4100805c7349606a920d96e54f2d16b2f0afa6b7cd5253967ccc9
languageName: node
linkType: hard
"@types/mime@npm:*":
version: 3.0.4
resolution: "@types/mime@npm:3.0.4"
@ -7483,6 +7490,7 @@ __metadata:
"@types/lodash": "npm:^4.14.202"
"@types/lodash.debounce": "npm:^4"
"@types/luxon": "npm:^3.4.2"
"@types/mime-types": "npm:^2.1.4"
"@types/morgan": "npm:^1.9.9"
"@types/node": "npm:18"
"@types/react": "npm:^18.2.66"