-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
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.
|
object
moduleobject
module
return ctor; | ||
} | ||
|
||
function define (className, baseClass, options): any { | ||
function define (className: string | undefined, baseClass: Constructor | null, options: Parameters<typeof CCClass>[0]): Constructor { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
cocos-engine/cocos/core/data/class.ts
Lines 286 to 297 in c9d2f14
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
cocos-engine/cocos/core/data/class.ts
Line 178 in c9d2f14
className = className || frame.script; |
There is much HACK code in this module :(
I try to add more type detail for it
@PPpro ❗ There was an error during the execution of the tasks. Please check the logs for more details. |
object
module@base/object
module
Re: #16375
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: