Browse Source

@uppy/core: fix some type errors (#5015)

Antoine du Hamel 1 năm trước cách đây
mục cha
commit
68af8a3c0f

+ 5 - 5
packages/@uppy/core/src/BasePlugin.ts

@@ -49,17 +49,17 @@ export default class BasePlugin<
 
   opts: Opts
 
-  id: string
+  id!: string
 
   defaultLocale: OptionalPluralizeLocale
 
-  i18n: I18n
+  i18n!: I18n
 
-  i18nArray: Translator['translateArray']
+  i18nArray!: Translator['translateArray']
 
-  type: string
+  type!: string
 
-  VERSION: string
+  VERSION!: string
 
   constructor(uppy: Uppy<M, B>, opts?: Opts) {
     this.uppy = uppy

+ 1 - 1
packages/@uppy/core/src/Restricter.ts

@@ -41,7 +41,7 @@ const defaultOptions = {
 class RestrictionError<M extends Meta, B extends Body> extends Error {
   isUserFacing: boolean
 
-  file: UppyFile<M, B>
+  file!: UppyFile<M, B>
 
   constructor(
     message: string,

+ 7 - 7
packages/@uppy/core/src/Uppy.ts

@@ -379,7 +379,7 @@ export class Uppy<M extends Meta, B extends Body> {
 
   defaultLocale: Locale
 
-  locale: Locale
+  locale!: Locale
 
   // The user optionally passes in options, but we set defaults for missing options.
   // We consider all options present after the contructor has run.
@@ -387,9 +387,9 @@ export class Uppy<M extends Meta, B extends Body> {
 
   store: NonNullableUppyOptions<M, B>['store']
 
-  i18n: I18n
+  i18n!: I18n
 
-  i18nArray: Translator['translateArray']
+  i18nArray!: Translator['translateArray']
 
   scheduledAutoProceed: ReturnType<typeof setTimeout> | null = null
 
@@ -839,7 +839,7 @@ export class Uppy<M extends Meta, B extends Body> {
     try {
       this.#restricter.validate(files, [file])
     } catch (err) {
-      return err
+      return err as any
     }
     return null
   }
@@ -1030,7 +1030,7 @@ export class Uppy<M extends Meta, B extends Body> {
         nextFilesState[newFile.id] = newFile
         validFilesToAdd.push(newFile)
       } catch (err) {
-        errors.push(err)
+        errors.push(err as any)
       }
     }
 
@@ -1042,7 +1042,7 @@ export class Uppy<M extends Meta, B extends Body> {
         validFilesToAdd,
       )
     } catch (err) {
-      errors.push(err)
+      errors.push(err as any)
 
       // If we have any aggregate error, don't allow adding this batch
       return {
@@ -2146,7 +2146,7 @@ export class Uppy<M extends Meta, B extends Body> {
    * Start an upload for all the files that are not currently being uploaded.
    */
   upload(): Promise<NonNullable<UploadResult<M, B>> | undefined> {
-    if (!this.#plugins.uploader?.length) {
+    if (!this.#plugins['uploader']?.length) {
       this.log('No uploader type plugins are used', 'warning')
     }