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

modify the userdata type of IExposedAttributes #17160

Merged
merged 2 commits into from
Jul 3, 2024

Conversation

whaqzhzd
Copy link
Contributor

@whaqzhzd whaqzhzd commented Jun 15, 2024

Replace the IExposedAttributes userdata types from Record < string, any > to interface IExposedAttributesUserData extends Record < string, any> {}. The advantage of this modification is that we can take advantage of the type namesakes interface merging feature of ts to achieve better type hints.

For example, we have a type file in which we define the following:

declare module "cc" {
  export namespace __private {
    export interface _cocos_core_data_utils_attribute_defines__IExposedAttributesUserData extends  my interface type {
       // other prototype
    }
  }
}

So when we use

@property({ type: property type, userData: { /*There will be our own defined type information. Very convenient/*  } }) _property: property type= null!;

Copy link

github-actions bot commented Jun 15, 2024

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -62594,8 +62594,10 @@
             name: string;
             displayOrder: number;
             style: string;
         }>;
+        export interface _cocos_core_data_utils_attribute_defines__IExposedAttributesUserData extends Record<string, any> {
+        }
         export interface _cocos_core_data_utils_attribute_defines__IExposedAttributes {
             /**
              * 指定属性的类型。
              */
@@ -62691,9 +62693,9 @@
             /**
              * @en User custom data, which can be obtained through the `CCClass.attr()` interface.
              * @zh 用户自定义数据,可以通过 `CCClass.attr()` 接口获取自定义数据。
              */
-            userData?: Record<string, any>;
+            userData?: _cocos_core_data_utils_attribute_defines__IExposedAttributesUserData;
             /**
              * 在允许的情况下,在编辑器中显示为一组单选按钮
              */
             radioGroup?: boolean;

@minggo minggo requested a review from dumganhar June 17, 2024 02:26
@@ -594,6 +593,7 @@ function parseAttributes (constructor: Function, attributes: PropertyStash, clas
parseSimpleAttribute('min', 'number');
parseSimpleAttribute('max', 'number');
parseSimpleAttribute('step', 'number');
parseSimpleAttribute('userData', 'object');
Copy link
Contributor

Choose a reason for hiding this comment

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

In the old logic, userData was exposed only in DEV mode.
Why does it need to be exposed in Release mode too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, in that case, I don't necessarily need him, I just happened to see such a field in the Property decorator, and from the comments, it doesn't seem to be limited to use under editor or dev. I'm just adding some class tolerance for my properties to do something later. Both so I can develop a new decorator to do this.

@dumganhar dumganhar merged commit 7c9776a into cocos:v3.8.5 Jul 3, 2024
10 checks passed
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.

None yet

2 participants