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

Rest Argument should be add. #25

Closed
sonygod opened this issue May 23, 2020 · 6 comments
Closed

Rest Argument should be add. #25

sonygod opened this issue May 23, 2020 · 6 comments
Labels
invalid This doesn't seem right

Comments

@sonygod
Copy link

sonygod commented May 23, 2020

code from cocos creator .d.ts

 export function Class(options?: {name?: string; extends?: Function; ctor?: Function; __ctor__?: Function; properties?: any; statics?: any; mixins?: Function[]; editor?: {executeInEditMode?: boolean; requireComponent?: Function; menu?: string; executionOrder?: number; disallowMultiple?: boolean; playOnFocus?: boolean; inspector?: string; icon?: string; help?: string; }; update?: Function; lateUpdate?: Function; onLoad?: Function; start?: Function; onEnable?: Function; onDisable?: Function; onDestroy?: Function; onFocusInEditor?: Function; onLostFocusInEditor?: Function; resetInEditor?: Function; onRestore?: Function; _getLocalBounds?: Function; }): Function;	

it's seem typescript only options this arguments but not limit other arguments

here is piece of haxe test code

class Main {
	public static var name:String = "main";

	static function main() {
		Cc.Class({
			'extends': Component,
			properties: {
				
			},

			onLoad: function() {
				
			},
			callback: function(event, customEventData) {
			
			},
			update: function(dt) {},
		});
	}
}

callback is not allow here in haxe,but js and typescript can .

maybe you should add some rest Argument for that and unlimit parms in Cc.Class

https://docs.cocos.com/creator/manual/en/components/button.html

@haxiomic
Copy link
Owner

haxiomic commented May 23, 2020

Rest arguments are supported but this function does not declare any

This function instead takes an object

The type of the object does not include a callback field

Haxe has stricter rules for structure unification than typescript and will complain sometimes about additional fields

This is not something dts2hx can change

You could open an issue on the creator type definitions to add the callback field

@haxiomic haxiomic added the invalid This doesn't seem right label May 23, 2020
@haxiomic
Copy link
Owner

haxiomic commented May 23, 2020

Here’s a related issue and explaination
HaxeFoundation/haxe#3192 (comment)

I think there’s an argument to be made for allowing extra fields for externs in haxe compiler (maybe we metadata)

@sonygod
Copy link
Author

sonygod commented May 23, 2020

Can you give an example?

@haxiomic
Copy link
Owner

haxiomic commented May 23, 2020

var options: {
    var field: String
} = {
    field: 'hello',
    extra: 'world', // this field is disallowed because it's not included in the structure
// this is done because generally if you're directly assigning to a structure like this, extra fields are usually a typo
}

This works however

var options = {
    field: 'hello',
    extra: 'world',
}
function call(options: Options);
call(options); // OK

I think if you wrap the field name in quotes it will probably work. Try this

Cc.Class({
    "callback": function(event, customEventData) {},
});

@sonygod
Copy link
Author

sonygod commented May 23, 2020

image

I think if you wrap the field name in quotes it will probably work.

no ,it's not work.

@haxiomic
Copy link
Owner

Ahh ok, nothing we can do then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants