diff --git a/@types/globals.d.ts b/@types/globals.d.ts index ebcf4ad465..750b84f324 100644 --- a/@types/globals.d.ts +++ b/@types/globals.d.ts @@ -38,51 +38,51 @@ interface Window { canvas: any; XMLHttpRequest: any; - mozRequestAnimationFrame (callback: any, element?: any): any; - oRequestAnimationFrame (callback: any, element?: any): any; - msRequestAnimationFrame (callback: any, element?: any): any; - cancelRequestAnimationFrame (callback: any, element?: any): any; - msCancelRequestAnimationFrame (callback: any, element?: any): any; - mozCancelRequestAnimationFrame (callback: any, element?: any): any; - oCancelRequestAnimationFrame (callback: any, element?: any): any; - webkitCancelRequestAnimationFrame (callback: any, element?: any): any; - msCancelAnimationFrame (callback: any, element?: any): any; - mozCancelAnimationFrame (callback: any, element?: any): any; - ocancelAnimationFrame (callback: any, element?: any): any; + mozRequestAnimationFrame(callback: any, element?: any): any; + oRequestAnimationFrame(callback: any, element?: any): any; + msRequestAnimationFrame(callback: any, element?: any): any; + cancelRequestAnimationFrame(callback: any, element?: any): any; + msCancelRequestAnimationFrame(callback: any, element?: any): any; + mozCancelRequestAnimationFrame(callback: any, element?: any): any; + oCancelRequestAnimationFrame(callback: any, element?: any): any; + webkitCancelRequestAnimationFrame(callback: any, element?: any): any; + msCancelAnimationFrame(callback: any, element?: any): any; + mozCancelAnimationFrame(callback: any, element?: any): any; + ocancelAnimationFrame(callback: any, element?: any): any; } -interface Document{ +interface Document { mozHidden: any; msHidden: any; webkitHidden: any; } -interface HTMLElement{ +interface HTMLElement { content: any; name: any; } -type ActiveXObject = new (s: string) => any; -declare const ActiveXObject: ActiveXObject; - declare type CompareFunction = (a: T, b: T) => number; declare type RecursivePartial = { [P in keyof T]?: - T[P] extends Array ? Array> : + T[P] extends Array ? Array> : T[P] extends ReadonlyArray ? ReadonlyArray> : RecursivePartial; }; -declare type TypedArray = Uint8Array | Uint8ClampedArray | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array | Float32Array | Float64Array; +declare type TypedArray = Uint8Array | Uint8ClampedArray | Int8Array | Uint16Array | +Int16Array | Uint32Array | Int32Array | Float32Array | Float64Array; -declare type TypedArrayConstructor = Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int8ArrayConstructor | Uint16ArrayConstructor | Int16ArrayConstructor | Uint32ArrayConstructor | Int32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor; +declare type TypedArrayConstructor = Uint8ArrayConstructor | Uint8ClampedArrayConstructor | +Int8ArrayConstructor | Uint16ArrayConstructor | Int16ArrayConstructor | Uint32ArrayConstructor | +Int32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor; declare interface IWritableArrayLike { readonly length: number; [index: number]: T; } -declare type Constructor = new(...args: any[]) => T; +declare type Constructor = new (...args: any[]) => T; /** * Alias of `Function` but suppress eslint warning. diff --git a/@types/webGL2.extras.d.ts b/@types/webGL2.extras.d.ts index 4468a18ad4..913b738e97 100644 --- a/@types/webGL2.extras.d.ts +++ b/@types/webGL2.extras.d.ts @@ -1,5 +1,4 @@ -interface EXT_color_buffer_float { -} +interface EXT_color_buffer_float {} interface EXT_disjoint_timer_query_webgl2 { readonly QUERY_COUNTER_BITS_EXT: GLenum; @@ -20,4 +19,4 @@ interface WEBGL_texture_storage_multisample { width: GLsizei, height: GLsizei, fixedsamplelocations: GLboolean): void; -} \ No newline at end of file +} diff --git a/cocos/core/asset-manager/downloader.ts b/cocos/core/asset-manager/downloader.ts index defb1ad65d..6f5c3ff151 100644 --- a/cocos/core/asset-manager/downloader.ts +++ b/cocos/core/asset-manager/downloader.ts @@ -110,7 +110,7 @@ const downloadCCONB = (url: string, options: IDownloadParseOptions, onComplete: const ccon = decodeCCONBinary(new Uint8Array(arrayBuffer)); onComplete(null, ccon); } catch (err) { - onComplete(err); + onComplete(err as Error); } }); }; @@ -155,7 +155,8 @@ const downloadBundle = (nameOrUrl: string, options: IBundleOptions, onComplete: /** * @en - * Control all download process, it is a singleton. All member can be accessed with `cc.assetManager.downloader` , it can download several types of files: + * Control all download process, it is a singleton. + * All member can be accessed with `cc.assetManager.downloader`, it can download several types of files: * 1. Text * 2. Image * 3. Audio @@ -326,7 +327,8 @@ export class Downloader { * * @example * downloader.register('.tga', (url, options, onComplete) => onComplete(null, null)); - * downloader.register({'.tga': (url, options, onComplete) => onComplete(null, null), '.ext': (url, options, onComplete) => onComplete(null, null)}); + * downloader.register({'.tga': (url, options, onComplete) => onComplete(null, null), + * '.ext': (url, options, onComplete) => onComplete(null, null)}); * */ public register (type: string, handler: DownloadHandler): void; @@ -360,8 +362,8 @@ export class Downloader { * @param onComplete.content - The downloaded file * * @example - * download('http://example.com/test.tga', '.tga', {onFileProgress: (loaded, total) => console.log(loaded/total)}, onComplete: (err) => console.log(err)); - * + * download('http://example.com/test.tga', '.tga', { onFileProgress: (loaded, total) => console.log(loaded/total) }, + * onComplete: (err) => console.log(err)); */ public download (id: string, url: string, type: string, options: IDownloadParseOptions, onComplete: CompleteCallback): void { // if it is downloaded, don't download again diff --git a/cocos/core/asset-manager/factory.ts b/cocos/core/asset-manager/factory.ts index dd376086f7..e339eb7706 100644 --- a/cocos/core/asset-manager/factory.ts +++ b/cocos/core/asset-manager/factory.ts @@ -48,13 +48,13 @@ export type CreateHandler = (id: string, data: any, options: IDownloadParseOptio function createImageAsset (id: string, data: HTMLImageElement, options: IDownloadParseOptions, onComplete: CompleteCallback) { let out: ImageAsset | null = null; - let err = null; + let err: Error | null = null; try { out = new ImageAsset(); out._nativeUrl = id; out._nativeAsset = data; } catch (e) { - err = e; + err = e as Error; } onComplete(err, out); } diff --git a/cocos/core/asset-manager/helper.ts b/cocos/core/asset-manager/helper.ts index 7c81067665..86e59d9cc9 100644 --- a/cocos/core/asset-manager/helper.ts +++ b/cocos/core/asset-manager/helper.ts @@ -146,7 +146,7 @@ export function transform (input: Request, options?: IOptions | null): string | for (const item of subTask.output) { item.recycle(); } - error(e.message, e.stack); + error((e as Error).message, (e as Error).stack); } subTask.recycle(); return urls.length > 1 ? urls : urls[0]; diff --git a/cocos/core/asset-manager/load.ts b/cocos/core/asset-manager/load.ts index a4e7533af7..5bb3acf9c9 100644 --- a/cocos/core/asset-manager/load.ts +++ b/cocos/core/asset-manager/load.ts @@ -224,7 +224,7 @@ function loadDepends (task: Task, asset: Asset, done: CompleteCallbackNoData) { onLoadedInvokedMap.add(asset); } } catch (e) { - error(`The asset ${uuid} is invalid for some reason, detail message: ${e.message}, stack: ${e.stack}`); + error(`The asset ${uuid} is invalid for some reason, detail message: ${(e as Error).message}, stack: ${(e as Error).stack!}`); if (EDITOR || PREVIEW) { if (asset instanceof Asset) { asset.initDefault(); diff --git a/cocos/core/asset-manager/parser.ts b/cocos/core/asset-manager/parser.ts index 26d9b638a6..76b2de9a31 100644 --- a/cocos/core/asset-manager/parser.ts +++ b/cocos/core/asset-manager/parser.ts @@ -217,7 +217,7 @@ export class Parser { throw new Error('Invalid magic number in PVR header'); } } catch (e) { - err = e; + err = e as Error; } onComplete(err, out); } @@ -245,7 +245,7 @@ export class Parser { format: 0, }; } catch (e) { - err = e; + err = e as Error; } onComplete(err, out); } @@ -273,9 +273,12 @@ export class Parser { const format = getASTCFormat(xdim, ydim); - const xsize = header[ASTC_HEADER_SIZE_X_BEGIN] + (header[ASTC_HEADER_SIZE_X_BEGIN + 1] << 8) + (header[ASTC_HEADER_SIZE_X_BEGIN + 2] << 16); - const ysize = header[ASTC_HEADER_SIZE_Y_BEGIN] + (header[ASTC_HEADER_SIZE_Y_BEGIN + 1] << 8) + (header[ASTC_HEADER_SIZE_Y_BEGIN + 2] << 16); - const zsize = header[ASTC_HEADER_SIZE_Z_BEGIN] + (header[ASTC_HEADER_SIZE_Z_BEGIN + 1] << 8) + (header[ASTC_HEADER_SIZE_Z_BEGIN + 2] << 16); + const xsize = header[ASTC_HEADER_SIZE_X_BEGIN] + (header[ASTC_HEADER_SIZE_X_BEGIN + 1] << 8) + + (header[ASTC_HEADER_SIZE_X_BEGIN + 2] << 16); + const ysize = header[ASTC_HEADER_SIZE_Y_BEGIN] + (header[ASTC_HEADER_SIZE_Y_BEGIN + 1] << 8) + + (header[ASTC_HEADER_SIZE_Y_BEGIN + 2] << 16); + const zsize = header[ASTC_HEADER_SIZE_Z_BEGIN] + (header[ASTC_HEADER_SIZE_Z_BEGIN + 1] << 8) + + (header[ASTC_HEADER_SIZE_Z_BEGIN + 2] << 16); // buffer = buffer.slice(ASTC_HEADER_LENGTH, buffer.byteLength); const astcData = new Uint8Array(buffer, ASTC_HEADER_LENGTH); @@ -288,7 +291,7 @@ export class Parser { format, }; } catch (e) { - err = e; + err = e as Error; } onComplete(err, out); } @@ -310,7 +313,7 @@ export class Parser { try { result = deserialize(file, options); } catch (e) { - err = e; + err = e as Error; } onComplete(err, result); } @@ -334,7 +337,8 @@ export class Parser { * * @example * parser.register('.tga', (file, options, onComplete) => onComplete(null, null)); - * parser.register({'.tga': (file, options, onComplete) => onComplete(null, null), '.ext': (file, options, onComplete) => onComplete(null, null)}); + * parser.register({'.tga': (file, options, onComplete) => onComplete(null, null), + * '.ext': (file, options, onComplete) => onComplete(null, null)}); * */ public register (type: string, handler: ParseHandler): void; diff --git a/cocos/core/asset-manager/preprocess.ts b/cocos/core/asset-manager/preprocess.ts index e7421f6d44..271a9aa953 100644 --- a/cocos/core/asset-manager/preprocess.ts +++ b/cocos/core/asset-manager/preprocess.ts @@ -68,11 +68,11 @@ export default function preprocess (task: Task, done: CompleteCallbackNoData) { // transform url const subTask = Task.create({ input: task.input, options: subOptions }); - let err = null; + let err: Error | null = null; try { task.output = task.source = transformPipeline.sync(subTask); } catch (e) { - err = e; + err = e as Error; for (let i = 0, l = subTask.output.length; i < l; i++) { subTask.output[i].recycle(); } diff --git a/cocos/core/asset-manager/utilities.ts b/cocos/core/asset-manager/utilities.ts index 66c7645d15..ff8ca7c770 100644 --- a/cocos/core/asset-manager/utilities.ts +++ b/cocos/core/asset-manager/utilities.ts @@ -110,7 +110,7 @@ export function getDepends (uuid: string, data: Asset | Record, exc depends.push({ ...info.nativeDep }); } } catch (e) { - error(e.message, e.stack); + error((e as Error).message, (e as Error).stack); } } diff --git a/cocos/core/assets/texture-base.ts b/cocos/core/assets/texture-base.ts index feee19669c..003362c8bf 100644 --- a/cocos/core/assets/texture-base.ts +++ b/cocos/core/assets/texture-base.ts @@ -39,6 +39,9 @@ import { Sampler, Texture, Device, Format, SamplerInfo, Address, Filter as GFXFi import { legacyCC } from '../global-exports'; import { errorID } from '../platform/debug'; import { murmurhash2_32_gc } from '../utils/murmurhash2_gc'; +import { ccenum } from '../value-types/enum'; + +ccenum(Format); const idGenerator = new IDGenerator('Tex'); /** diff --git a/cocos/core/data/ccon.ts b/cocos/core/data/ccon.ts index d5f600e447..c0d5cff5c2 100644 --- a/cocos/core/data/ccon.ts +++ b/cocos/core/data/ccon.ts @@ -119,7 +119,7 @@ export function decodeCCONBinary (bytes: Uint8Array) { try { json = JSON.parse(jsonString); } catch (err) { - throw new InvalidCCONError(err); + throw new InvalidCCONError(err as string); } const chunks: Uint8Array[] = []; diff --git a/cocos/core/gfx/base/define.ts b/cocos/core/gfx/base/define.ts index 8afbb8fb43..bed7d9164a 100644 --- a/cocos/core/gfx/base/define.ts +++ b/cocos/core/gfx/base/define.ts @@ -28,7 +28,6 @@ * @module gfx */ -import { ccenum } from '../../value-types/enum'; import { Buffer } from './buffer'; import { DescriptorSetLayout } from './descriptor-set-layout'; import { Queue } from './queue'; @@ -1789,8 +1788,6 @@ export class DynamicStates { * ========================= !DO NOT CHANGE THE ABOVE SECTION MANUALLY! ========================= */ -ccenum(Format); - /** * @en GFX base object. * @zh GFX 基类对象。 diff --git a/cocos/core/gfx/webgl/webgl-commands.ts b/cocos/core/gfx/webgl/webgl-commands.ts index bef3094b96..69d35c28a6 100644 --- a/cocos/core/gfx/webgl/webgl-commands.ts +++ b/cocos/core/gfx/webgl/webgl-commands.ts @@ -451,7 +451,7 @@ export abstract class WebGLCmdObject { this.cmdType = type; } - public abstract clear (); + public abstract clear (): void; } export class WebGLCmdBeginRenderPass extends WebGLCmdObject { diff --git a/cocos/core/gfx/webgl/webgl-swapchain.ts b/cocos/core/gfx/webgl/webgl-swapchain.ts index 11fb2eb027..289a350a7b 100644 --- a/cocos/core/gfx/webgl/webgl-swapchain.ts +++ b/cocos/core/gfx/webgl/webgl-swapchain.ts @@ -24,16 +24,18 @@ */ import { ALIPAY, RUNTIME_BASED, BYTEDANCE, WECHAT, LINKSURE, QTT, COCOSPLAY, HUAWEI, EDITOR } from 'internal:constants'; -import { macro, warnID, warn, debug } from '../../platform'; -import { sys } from '../../platform/sys'; +import { warnID, warn, debug } from '../../platform/debug'; +import { macro } from '../../platform/macro'; import { WebGLCommandAllocator } from './webgl-command-allocator'; import { WebGLStateCache } from './webgl-state-cache'; import { WebGLTexture } from './webgl-texture'; import { Format, TextureInfo, TextureFlagBit, TextureType, TextureUsageBit, BufferTextureCopy, SwapchainInfo, SurfaceTransform } from '../base/define'; -import { BrowserType, OS } from '../../../../pal/system-info/enum-type'; +import { BrowserType } from '../../../../pal/system-info/enum-type/browser-type'; +import { OS } from '../../../../pal/system-info/enum-type/operating-system'; import { Swapchain } from '../base/swapchain'; import { IWebGLExtensions, WebGLDeviceManager } from './webgl-define'; +import { legacyCC } from '../../global-exports'; const eventWebGLContextLost = 'webglcontextlost'; @@ -128,17 +130,17 @@ export function getExtensions (gl: WebGLRenderingContext) { // eslint-disable-next-line no-lone-blocks { // iOS 14 browsers crash on getExtension('WEBGL_compressed_texture_astc') - if (sys.os !== OS.IOS || sys.osMainVersion !== 14 || !sys.isBrowser) { + if (legacyCC.sys.os !== OS.IOS || legacyCC.sys.osMainVersion !== 14 || !legacyCC.sys.isBrowser) { res.WEBGL_compressed_texture_astc = getExtension(gl, 'WEBGL_compressed_texture_astc'); } // UC browser instancing implementation doesn't work - if (sys.browserType === BrowserType.UC) { + if (legacyCC.sys.browserType === BrowserType.UC) { res.ANGLE_instanced_arrays = null; } // bytedance ios depth texture implementation doesn't work - if (BYTEDANCE && sys.os === OS.IOS) { + if (BYTEDANCE && legacyCC.sys.os === OS.IOS) { res.WEBGL_depth_texture = null; } @@ -150,8 +152,8 @@ export function getExtensions (gl: WebGLRenderingContext) { } // some earlier version of iOS and android wechat implement gl.detachShader incorrectly - if ((sys.os === OS.IOS && sys.osMainVersion <= 10) - || (WECHAT && sys.os === OS.ANDROID)) { + if ((legacyCC.sys.os === OS.IOS && legacyCC.sys.osMainVersion <= 10) + || (WECHAT && legacyCC.sys.os === OS.ANDROID)) { res.destroyShadersImmediately = false; } diff --git a/cocos/core/gfx/webgl2/webgl2-commands.ts b/cocos/core/gfx/webgl2/webgl2-commands.ts index f3fcc8fa72..06b0e35e75 100644 --- a/cocos/core/gfx/webgl2/webgl2-commands.ts +++ b/cocos/core/gfx/webgl2/webgl2-commands.ts @@ -24,8 +24,7 @@ */ import { CachedArray } from '../../memop/cached-array'; -import { error, errorID } from '../../platform'; -import { debug } from '../../platform/debug'; +import { error, errorID, debug } from '../../platform/debug'; import { BufferUsageBit, ColorMask, CullMode, DynamicStateFlagBit, Filter, Format, TextureType, Type, FormatInfo, FormatInfos, FormatSize, LoadOp, MemoryUsageBit, SampleCount, ShaderStageFlagBit, TextureFlagBit, @@ -635,7 +634,7 @@ export abstract class WebGL2CmdObject { this.cmdType = type; } - public abstract clear (); + public abstract clear (): void; } export class WebGL2CmdBeginRenderPass extends WebGL2CmdObject { diff --git a/cocos/core/gfx/webgl2/webgl2-swapchain.ts b/cocos/core/gfx/webgl2/webgl2-swapchain.ts index 270901d11b..ff7339c2d2 100644 --- a/cocos/core/gfx/webgl2/webgl2-swapchain.ts +++ b/cocos/core/gfx/webgl2/webgl2-swapchain.ts @@ -24,7 +24,8 @@ */ import { EDITOR } from 'internal:constants'; -import { macro, warnID, warn, debug } from '../../platform'; +import { warnID, warn, debug } from '../../platform/debug'; +import { macro } from '../../platform/macro'; import { WebGL2StateCache } from './webgl2-state-cache'; import { WebGL2Texture } from './webgl2-texture'; import { Format, TextureInfo, TextureFlagBit, TextureType, diff --git a/cocos/core/memop/cached-array.ts b/cocos/core/memop/cached-array.ts index e0ef198aeb..3dc25dc810 100644 --- a/cocos/core/memop/cached-array.ts +++ b/cocos/core/memop/cached-array.ts @@ -53,7 +53,7 @@ export class CachedArray { */ public length = 0; - private _compareFn; + private _compareFn?: (a: T, b: T) => number; /** * @param length Initial length @@ -62,12 +62,7 @@ export class CachedArray { constructor (length: number, compareFn?: (a: T, b: T) => number) { this.array = new Array(length); this.length = 0; - - if (compareFn !== undefined) { - this._compareFn = compareFn; - } else { - this._compareFn = (a: number, b: number) => a - b; - } + this._compareFn = compareFn; } /**