Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta: upgrade to TypeScript 4.8 #4048

Merged
merged 5 commits into from Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/package.json
Expand Up @@ -52,7 +52,7 @@
"prompts": "^2.4.2",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"typescript": "~4.7",
"typescript": "~4.8",
"vue": "^3.2.33"
}
}
4 changes: 2 additions & 2 deletions examples/angular-example/package.json
Expand Up @@ -36,7 +36,7 @@
"@angular-eslint/eslint-plugin-template": "^14.0.2",
"@angular-eslint/schematics": "^14.0.2",
"@angular-eslint/template-parser": "^14.0.2",
"@angular/cli": "~14.1.2",
"@angular/cli": "~14.2.0",
"@angular/compiler-cli": "^14.1.0",
"@types/jasmine": "~4.0.0",
"eslint": "^8.0.0",
Expand All @@ -49,6 +49,6 @@
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"typescript": "~4.7"
"typescript": "~4.8"
}
}
2 changes: 1 addition & 1 deletion examples/svelte-example/package.json
Expand Up @@ -28,7 +28,7 @@
"svelte-check": "^1.6.0",
"svelte-preprocess": "^4.6.1",
"tslib": "^2.0.0",
"typescript": "~4.7"
"typescript": "~4.8"
},
"dependencies": {
"@uppy/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -104,7 +104,7 @@
"stylelint-scss": "^4.0.0",
"tar": "^6.1.0",
"tsd": "^0.22.0",
"typescript": "~4.7",
"typescript": "~4.8",
"vue-template-compiler": "workspace:*"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/angular/package.json
Expand Up @@ -56,6 +56,6 @@
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"ng-packagr": "^13.0.0",
"typescript": "~4.7"
"typescript": "~4.8"
}
}
2 changes: 1 addition & 1 deletion packages/@uppy/companion/package.json
Expand Up @@ -85,7 +85,7 @@
"jest": "^28.0.0",
"nock": "^13.1.3",
"supertest": "6.2.4",
"typescript": "~4.7"
"typescript": "~4.8"
},
"files": [
"bin/",
Expand Down
43 changes: 27 additions & 16 deletions packages/@uppy/core/types/index.d.ts
Expand Up @@ -21,7 +21,7 @@ export type FileProgress = UppyUtils.FileProgress;
export type FileRemoveReason = 'removed-by-user' | 'cancel-all';

// Replace the `meta` property type with one that allows omitting internal metadata addFile() will add that
type UppyFileWithoutMeta<TMeta, TBody> = OmitKey<
type UppyFileWithoutMeta<TMeta extends IndexedObject<any>, TBody extends IndexedObject<any>> = OmitKey<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid a lot of duplication here by creating a new type that already extends it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC here we are defining the type TMeta, so I don't think that's an option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If TMeta is always with extends IndexedObject<any>, it can become the new type. If there are still exceptions, we can create a new type with combines the two and use those where needed in this file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm defining TMeta here, I don't think I can "make it a new type", or I don't understand what you mean.

UppyFile<TMeta, TBody>,
'meta'
>
Expand All @@ -36,17 +36,23 @@ export type Store = UppyUtils.Store

export type InternalMetadata = UppyUtils.InternalMetadata

export interface UploadedUppyFile<TMeta, TBody> extends UppyFile<TMeta, TBody> {
export interface UploadedUppyFile<
TMeta extends IndexedObject<any>,
TBody extends IndexedObject<any>
> extends UppyFile<TMeta, TBody> {
uploadURL: string
}

export interface FailedUppyFile<TMeta, TBody> extends UppyFile<TMeta, TBody> {
export interface FailedUppyFile<
TMeta extends IndexedObject<any>,
TBody extends IndexedObject<any>
> extends UppyFile<TMeta, TBody> {
error: string
}

export interface AddFileOptions<
TMeta = IndexedObject<any>,
TBody = IndexedObject<any>
TMeta extends IndexedObject<any> = IndexedObject<any>,
TBody extends IndexedObject<any> = IndexedObject<any>
> extends Partial<UppyFileWithoutMeta<TMeta, TBody>> {
// `.data` is the only required property here.
data: Blob | File
Expand Down Expand Up @@ -204,22 +210,27 @@ export interface SuccessResponse {
}

export type GenericEventCallback = () => void;
export type FileAddedCallback<TMeta> = (file: UppyFile<TMeta>) => void;
export type FilesAddedCallback<TMeta> = (files: UppyFile<TMeta>[]) => void;
export type FileRemovedCallback<TMeta> = (file: UppyFile<TMeta>, reason: FileRemoveReason) => void;
export type FileAddedCallback<TMeta extends IndexedObject<any>> = (file: UppyFile<TMeta>) => void;
export type FilesAddedCallback<TMeta extends IndexedObject<any>> = (files: UppyFile<TMeta>[]) => void;
export type FileRemovedCallback<TMeta extends IndexedObject<any>> =
(file: UppyFile<TMeta>, reason: FileRemoveReason) => void;
export type UploadCallback = (data: { id: string, fileIDs: string[] }) => void;
export type ProgressCallback = (progress: number) => void;
export type PreProcessCompleteCallback<TMeta> = (file: UppyFile<TMeta> | undefined) => void;
export type UploadProgressCallback<TMeta> = (file: UppyFile<TMeta> | undefined, progress: FileProgress) => void;
export type UploadSuccessCallback<TMeta> = (file: UppyFile<TMeta> | undefined, response: SuccessResponse) => void
export type UploadCompleteCallback<TMeta> = (result: UploadResult<TMeta>) => void
export type PreProcessCompleteCallback<TMeta extends IndexedObject<any>> = (file: UppyFile<TMeta> | undefined) => void;
export type UploadProgressCallback<TMeta extends IndexedObject<any>> =
(file: UppyFile<TMeta> | undefined, progress: FileProgress) => void;
export type UploadSuccessCallback<TMeta extends IndexedObject<any>> =
(file: UppyFile<TMeta> | undefined, response: SuccessResponse) => void
export type UploadCompleteCallback<TMeta extends IndexedObject<any>> = (result: UploadResult<TMeta>) => void
export type ErrorCallback = (error: Error) => void;
export type UploadErrorCallback<TMeta> = (file: UppyFile<TMeta> | undefined, error: Error, response?: ErrorResponse) => void;
export type UploadErrorCallback<TMeta extends IndexedObject<any>> =
(file: UppyFile<TMeta> | undefined, error: Error, response?: ErrorResponse) => void;
export type UploadRetryCallback = (fileID: string) => void;
export type RetryAllCallback = (fileIDs: string[]) => void;
export type RestrictionFailedCallback<TMeta> = (file: UppyFile<TMeta> | undefined, error: Error) => void;
export type RestrictionFailedCallback<TMeta extends IndexedObject<any>> =
(file: UppyFile<TMeta> | undefined, error: Error) => void;

export interface UppyEventMap<TMeta = Record<string, unknown>> {
export interface UppyEventMap<TMeta extends IndexedObject<any> = Record<string, unknown>> {
'file-added': FileAddedCallback<TMeta>
'files-added': FilesAddedCallback<TMeta>
'file-removed': FileRemovedCallback<TMeta>
Expand Down Expand Up @@ -349,7 +360,7 @@ export class Uppy {

getID(): string

use<TOptions, TInstance extends UIPlugin | BasePlugin<TOptions>>(
use<TOptions, TInstance extends UIPlugin | BasePlugin>(
pluginClass: new (uppy: this, opts: TOptions) => TInstance,
opts?: TOptions
): this
Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/dashboard/types/index.d.ts
@@ -1,4 +1,4 @@
import type { PluginOptions, UIPlugin, PluginTarget, UppyFile, GenericEventCallback } from '@uppy/core'
import type { PluginOptions, UIPlugin, PluginTarget, UppyFile, IndexedObject } from '@uppy/core'
import type { StatusBarLocale } from '@uppy/status-bar'
import type { ThumbnailOptions } from '@uppy/thumbnail-generator'
import DashboardLocale from './generatedLocale'
Expand Down Expand Up @@ -86,8 +86,8 @@ export default Dashboard

// Events

export type DashboardFileEditStartCallback<TMeta> = (file?: UppyFile<TMeta>) => void;
export type DashboardFileEditCompleteCallback<TMeta> = (file?: UppyFile<TMeta>) => void;
export type DashboardFileEditStartCallback<TMeta extends IndexedObject<any>> = (file?: UppyFile<TMeta>) => void;
export type DashboardFileEditCompleteCallback<TMeta extends IndexedObject<any>> = (file?: UppyFile<TMeta>) => void;
declare module '@uppy/core' {
export interface UppyEventMap<TMeta> {
'dashboard:modal-open': GenericEventCallback
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/thumbnail-generator/types/index.d.ts
@@ -1,4 +1,4 @@
import type { PluginOptions, UIPlugin, UppyFile } from '@uppy/core'
import type { IndexedObject, PluginOptions, UIPlugin, UppyFile } from '@uppy/core'

import ThumbnailGeneratorLocale from './generatedLocale'

Expand All @@ -20,7 +20,7 @@ export default ThumbnailGenerator

// Events

export type ThumbnailGeneratedCallback<TMeta> = (
export type ThumbnailGeneratedCallback<TMeta extends IndexedObject<any>> = (
file: UppyFile<TMeta>,
preview: string
) => void
Expand Down