Skip to content

Adding support for intersection types #461

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

Closed
natevoci opened this issue Mar 29, 2017 · 5 comments
Closed

Adding support for intersection types #461

natevoci opened this issue Mar 29, 2017 · 5 comments
Labels
help wanted Contributions are especially encouraged

Comments

@natevoci
Copy link
Contributor

I noticed that intersection types were not supported in the json output so I thought I'd have a go at adding support myself. I've got it almost working by copying the code used for unions, but I'm not getting the 'id' values and since I'm new to the typedoc code base, and node programming, I thought I'd ask for a bit of advice on the direction to take.

Here's the commit of what I've done so far
natevoci@2c0589e

I've been testing with this typescript file

export interface IBar {
	bar?: string;
}

export interface IFoo {
	foo?: string;
}

type IIntersectionFooBar = IFoo & IBar;
let unionFooBar: IFoo | IBar;

The json output for the type of unionFooBar is

"type": {
	"type": "union",
	"types": [
		{
			"type": "reference",
			"name": "IFoo",
			"id": 4
		},
		{
			"type": "reference",
			"name": "IBar",
			"id": 2
		}
	]
}

but for the IIntersectionFooBar type I get

"type": {
	"type": "intersection",
	"types": [
		{
			"type": "reference",
			"name": "IFoo"
		},
		{
			"type": "reference",
			"name": "IBar"
		}
	]
}

as you can see the 'id' values are missing.

I'm guessing this is happening because this.reflection is not set in the ReferenceType class and the toObject() function has this

        if (this.reflection) {
            result.id = this.reflection.id;
        }

but I haven't been able to find where the ReferenceType constructor is being called to understand if the 3rd 'reflection' parameter of the constructor can be set.

Am I on the right track? Is what i'm trying to do even possible? Any advice or tips on what to look at next would be appreciated.

@blakeembrey blakeembrey added enhancement help wanted Contributions are especially encouraged labels Apr 3, 2017
@natevoci
Copy link
Contributor Author

Anyone?

Even some tips or tricks from your experience of debugging typedoc would be handy for me figuring it out.

@aciccarello
Copy link
Collaborator

The JSON output is helpful when trying to understand how your code was parsed. See the --json argument

@natevoci
Copy link
Contributor Author

Hi aciccarello. Thanks for replying.

As you can see in my original post I'm already getting the json output. I'm hoping someone with experience developing typedoc can help me out with whether what I'm trying to fix in the source code is possible. In lieu of that, some tips on debugging typedoc would be helpful. I've set up vsCode as my debugger and so far I haven't found a good spot to put a breakpoint. Even with the small sample programs I'm running it with there are hundreds of tokens to step through to figure out what's going on.

I'm sure I'll get there eventually, but I'd hoped with a bit of advice I could speed up the process.

@aciccarello
Copy link
Collaborator

Oh sorry, I should have read more carefully. I'd say you are on the right track. But since someone else wrote most of the source I can't give you too much more info.

@natevoci
Copy link
Contributor Author

Thanks to the recent changes from @makana #482 intersection types are now working properly, so I'm closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions are especially encouraged
Projects
None yet
Development

No branches or pull requests

4 participants