Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Custom types are not found when populating parameters in functions #21

Closed
rollerkazike opened this issue Jul 2, 2017 · 3 comments
Closed

Comments

@rollerkazike
Copy link

Trying to generate the SWC file for the PixiJS library d.ts definition found in:

https://github.com/pixijs/pixi-typescript

I got the error:

Error: Type interaction.InteractionEventTypes not found for parameter event in function on.

The type seems to be correctly defined in the namespace, and VSCode correctly represents it with no error warnings:

export namespace interaction {
...
        type InteractionPointerEvents = "pointerdown" | "pointercancel" | "pointerup" | "pointertap" | "pointerupoutside" | "pointermove" | "pointerover" | "pointerout";
        type InteractionTouchEvents = "touchstart" | "touchcancel" | "touchend" | "touchendoutside" | "touchmove" | "tap";
        type InteractionMouseEvents = "rightdown" | "mousedown" | "rightup" | "mouseup" | "rightclick" | "click" | "rightupoutside" | "mouseupoutside" | "mousemove" | "mouseover" | "mouseout" | "mouseover";
        type InteractionEventTypes = InteractionPointerEvents | InteractionTouchEvents | InteractionMouseEvents;
}

I changed all references of this type to string (all located in the DisplayObject class) and the tool correctly generates the SWC file.

@joshtynjala
Copy link
Member

Thanks for the bug report. Yeah, dts2as isn't always great at using many TypeScript features together when ActionScript doesn't have them too, like this case with type aliases, unions and string literal types. I've gotten most of them to work alone, but edge cases that combine many features at once tend to break.

@rollerkazike
Copy link
Author

You are welcome!

I see... I was thinking that may be the case, but luckily working a little on the d.ts file does the trick, so that's great. In the end with these kind of things, you can always set the type as 'any' and go ahead with that...

Maybe the dts2as tool, as a last resort option if a type cannot be resolved, set it as 'any' and throw a warning in the console? It can even be an option you can specify when running the tool :)

Thanks again Josh for the help!

@joshtynjala
Copy link
Member

That's a good idea about falling back to any when the type can't be found (with a warning, of course).

Another thing you can do is specify the -outDir option to have dts2as output uncompiled ActionScript instead of trying to compile the SWC. Then you can make tweaks to the .as files and compile the SWC yourself. It may be easier to tweak the .d.ts files instead of the .as files, though.

joshtynjala added a commit that referenced this issue Jul 13, 2017
…issing, print an error and default to Object to try to compile anyway (same for missing interfaces) (reference #21)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants