elsassph / hxtsdgen

TypeScript declaration file generator for Haxe JavaScript output target
65 stars 12 forks source link

typedef support #3

Closed francescoagati closed 5 years ago

francescoagati commented 5 years ago

hi, there is mode for add support for types export?

back2dos commented 5 years ago

Across all targets, typedefs don't exist at compile time. What's your use case?

francescoagati commented 5 years ago

imagine this type in haxe

@:expose typedef Player = {name:String,surname:String}

in javascript with jsdoc and typescript i want to import the type player generated from haxe in the file App.d.ts in this mode for example

/**
 * @param player { import("./App.d.ts").Player }
 */
function walk(player) {
    console.log(`Walking ${p.name}...`);
}
fullofcaffeine commented 5 years ago

Across all targets, typedefs don't exist at compile time

@back2dos So that means they don't exist in the AST? So it'd be impossible to even get hold of them to generate TS type defs, it appears.

nadako commented 5 years ago

typedefs exist in AST. from them we should generate TS interface if it's a typedef to a structure, or type if it's some other type

elsassph commented 5 years ago

The problem is that typedefs don't have a name in the AST, isn't it?

nadako commented 5 years ago

They do, that's their purpose - to give a name to a type :)

It's here https://github.com/nadako/hxtsdgen/blob/8244c170445c7f763045f2eca18a1b77beab8688/src/hxtsdgen/TypeRenderer.hx#L69

elsassph commented 5 years ago

Typedefs are now supported \o/

francescoagati commented 5 years ago

sorry for late response @elsassph now i have tested the typedef support in a big project. and all work really good thanks