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

optimize: fix eslint in @base/object module #16380

Merged
merged 6 commits into from
Oct 9, 2023
Merged

Conversation

PPpro
Copy link
Contributor

@PPpro PPpro commented Oct 9, 2023

Re: #16375

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

@PPpro PPpro changed the title fix eslint int object module fix eslint in object module Oct 9, 2023
@github-actions
Copy link

github-actions bot commented Oct 9, 2023

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -20208,23 +20208,23 @@
         export const string: __private._cocos_core_data_decorators_utils__LegacyPropertyDecorator;
     }
     export function CCClass<TFunction>(options: {
         name?: string;
-        extends: null | (Function & {
+        extends: null | (__private.____packages_cc_ambient_types_src_globals__Constructor & {
             __props__?: any;
             _sealed?: boolean;
         });
         ctor: TFunction;
-        properties?: any;
+        properties?: Record<string, __private._cocos_core_data_class_stash__PropertyStash>;
         editor?: any;
     }): any;
     export namespace CCClass {
         export var _isCCClass: (constructor: any) => boolean;
-        export var fastDefine: (className: any, constructor: any, serializableFields: any) => void;
+        export var fastDefine: (className: string, constructor: __private.____packages_cc_ambient_types_src_globals__Constructor<unknown>, serializableFields: Record<string, unknown>) => void;
         export var Attr: typeof __private._cocos_core_data_utils_attribute;
         export var attr: typeof __private._cocos_core_data_utils_attribute.attr;
         export var isCCClassOrFastDefined: typeof __private._cocos_core_data_class__isCCClassOrFastDefined;
-        export var getInheritanceChain: (constructor: any) => any[];
+        export var getInheritanceChain: (constructor: __private.____packages_cc_ambient_types_src_globals__Constructor<unknown>) => any[];
         export var isArray: (defaultVal: any) => boolean;
         export var getDefault: (defaultVal: any) => any;
         export var escapeForJS: (s: any) => string;
         export var IDENTIFIER_RE: RegExp;
@@ -22232,9 +22232,9 @@
         number,
         number
     ];
     export function setPropertyEnumType(objectOrConstructor: object, propertyName: string, enumType: __private._cocos_core_value_types_enum__EnumType): void;
-    export function setPropertyEnumTypeOnAttrs(attrs: Record<string, any>, propertyName: string, enumType: __private._cocos_core_value_types_enum__EnumType): void;
+    export function setPropertyEnumTypeOnAttrs(attrs: Record<string, unknown>, propertyName: string, enumType: __private._cocos_core_value_types_enum__EnumType): void;
     export function isCCObject(object: any): object is CCObject;
     export function isValid(value: any, strictMode?: boolean): boolean;
     export namespace js {
         /**
@@ -61915,11 +61915,34 @@
             default: T;
             constructor(name: string, defaultValue: T);
             toString(): string;
         }
+        export interface _cocos_core_data_class_stash__PropertyStash extends _cocos_core_data_utils_attribute_defines__IExposedAttributes {
+            /**
+             * The property's default value.
+             */
+            default?: unknown;
+            /**
+             * The property's getter, if it's an accessor.
+             */
+            get?: () => unknown;
+            /**
+             * The property's setter, if it's an accessor.
+             */
+            set?: (value: unknown) => void;
+            /**
+             * Reserved for deprecated usage.
+             */
+            _short?: unknown;
+            /**
+             * Some decorators may write this internal slot. See `PropertyStashInternalFlag`.
+             */
+            __internalFlags: number;
+        }
         namespace _cocos_core_data_utils_attribute {
+            /// <reference types="cc-ambient-types" />
             export const DELIMETER = "$_$";
-            export function createAttrsSingle(owner: Object, superAttrs?: any): any;
+            export function createAttrsSingle(owner: Record<string | number, unknown>, superAttrs?: unknown): any;
             /**
              * @param subclass Should not have '__attrs__'.
              */
             export function createAttrs(subclass: any): any;
@@ -62018,10 +62041,10 @@
              * array = [];
              * ```
              */
             export const CCString: _cocos_core_data_utils_attribute__PrimitiveType<string>;
-            export function getTypeChecker_ET(type: string, attributeName: string): (constructor: Function, mainPropertyName: string) => void;
-            export function getObjTypeChecker_ET(typeCtor: any): (classCtor: any, mainPropName: any) => void;
+            export function getTypeChecker_ET(type: string, attributeName: string): (constructor: ____packages_cc_ambient_types_src_globals__Constructor, mainPropertyName: string) => void;
+            export function getObjTypeChecker_ET(typeCtor: any): (classCtor: ____packages_cc_ambient_types_src_globals__Constructor, mainPropName: string) => void;
         }
         /**
          * Tag the class with any meta attributes, then return all current attributes assigned to it.
          * This function holds only the attributes, not their implementations.

@PPpro PPpro requested a review from minggo October 9, 2023 08:29
@PPpro PPpro changed the title fix eslint in object module optimize: fix eslint in object module Oct 9, 2023
return ctor;
}

function define (className, baseClass, options): any {
function define (className: string | undefined, baseClass: Constructor | null, options: Parameters<typeof CCClass>[0]): Constructor {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why class name can be undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not a good interface design, but as it is used in CCClass method, it should be typeof string | undefined

export function CCClass<TFunction> (options: {
name?: string;
extends: null | (Function & { __props__?: any; _sealed?: boolean });
ctor: TFunction;
properties?: any;
editor?: any;
}): any {
let name = options.name;
const base = options.extends/* || CCObject */;
// create constructor
const cls = define(name, base, options);

Copy link
Contributor

Choose a reason for hiding this comment

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

Can it work if passing undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, actually in the past, undefined was often passed in

Copy link
Contributor Author

@PPpro PPpro Oct 9, 2023

Choose a reason for hiding this comment

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

I think this line fix the undefined issue

className = className || frame.script;

There is much HACK code in this module :(
I try to add more type detail for it

@PPpro PPpro marked this pull request as draft October 9, 2023 08:40
@PPpro PPpro marked this pull request as ready for review October 9, 2023 09:10
@minggo minggo merged commit 8d63787 into cocos:develop Oct 9, 2023
9 checks passed
@github-actions
Copy link

github-actions bot commented Oct 9, 2023

@PPpro ❗ There was an error during the execution of the tasks. Please check the logs for more details.

@PPpro PPpro deleted the dev-obj branch October 9, 2023 10:00
@PPpro PPpro changed the title optimize: fix eslint in object module optimize: fix eslint in @base/object module Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants