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

Typedoc does not include props from an interface when Omit is used #1094

Closed
1 task
sylvesteraswin opened this issue Sep 14, 2019 · 7 comments
Closed
1 task
Labels
bug Functionality does not match expectation

Comments

@sylvesteraswin
Copy link

sylvesteraswin commented Sep 14, 2019

In the extendedTypes of Props2 I get something similar to the below, but there is no id: 88 in the generated JSON.

"extendedTypes": [{
	"type": "reflection",
	"declaration": {
		"id": 88,
		"name": "__type",
		"kind": 65536,
		"kindString": "Type literal",
		"flags": {},
		"sources": [{
			"fileName": "fileName",
			"line": 14,
			"character": 43
		}]
	}
}],

Expected Behavior

I get only c:number as props in Props2.

Actual Behavior

Props2 to have a: string, b: string and c: number as its interface.

Steps to reproduce the bug

export interface Prop1 {
 a: string;
 b: string;
 c: string;
}

export interface Prop2 extends Omit<Prop1, "c"> {
 c: number;
}
typedoc --out typedoc ./file.tsx --theme minimal --mode modules

Environment

  • Typedoc version: 0.15.0
  • Node.js version: v11.15.0
  • OS: MacOS 10.14.6
@sylvesteraswin sylvesteraswin added the bug Functionality does not match expectation label Sep 14, 2019
@sylvesteraswin sylvesteraswin changed the title Typedoc does not induce props from an interface when Omit is used Typedoc does not include props from an interface when Omit is used Sep 15, 2019
@sylvesteraswin
Copy link
Author

sylvesteraswin commented Sep 15, 2019

@aciccarello what are your thoughts on this bug?

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Sep 21, 2019

This is a weird bug... There appears to be a couple issues:

  1. Extending from a type literal instead of an interface / class doesn't work - I'm guessing the theme assumes that extends will only occur with a type reference, which Omit<Prop1, 'c'> is not. Fixing this should at least allow "Type literal" to appear in the hierarchy section of the docs.
  2. Type literals which appear only in extend clauses are incorrectly converted - it is missing information about the type, not sure why this is. Unfortunately type aliases are rather like C's macros. They are resolved incredibly early in the compilation process and are difficult to detect & extract information about.

@vkefallinos
Copy link

vkefallinos/typedoc@ef812b1
I did a rough implementation to add Omit handling. It works but this code can't be merged by any means.

@MasterKale
Copy link

MasterKale commented Jul 22, 2020

I figured I'd chime in with my experience with this issue.

I have a series of interfaces that extends Omit<> interfaces in the dom TypeScript library:

export interface PublicKeyCredentialUserEntityJSON extends Omit <
PublicKeyCredentialUserEntity, 'id'
> {
  id: Base64URLString;
}

Here's PublicKeyCredentialUserEntity in node_modules/typescript/lib/lib.dom.d.ts:

interface PublicKeyCredentialUserEntity extends PublicKeyCredentialEntity {
    displayName: string;
    id: BufferSource;
}

The resulting documentation for this interface fails to list any information about PublicKeyCredentialUserEntity, instead showing an empty object:

Screen Shot 2020-07-22 at 12 04 48 PM

Environment

@codycuellar
Copy link

I get the exact same output as @MasterKale but using Pick, also on 0.17.0-3.

While I know next to nothing about the internal code of typedoc, I have noticed (I believe is in the theme stage) that if you extend an interface which is not exported, the theme has nothing to link inherited members from and instead list them inherited from itself. For instance:

interface Foo {
    one: number;
    two: number;
}

export interface Bar extends Foo {
    three: string;
}

Typedoc creates a bar.html page for the Bar interface, but not for Foo which isn't exported. The HTML displays the inherited property one, but says it is inherited from Bar itself which is clearly incorrect, but is understandable why it's doing that since there's no HTML file to link Foo.one.

Screen Shot 2020-10-29 at 10 31 47 AM

Regarding the Pick and Omit issue, my best guess is that since Bar extends Pick<Foo, 'one'>effectively generates an anonymous object that isn't kept track of during the plugin reflection resolving stage, it never even adds the properties to the objects that get passed off to the theme.

However, it gets more interesting when you get the same result if inheriting from an exported type. Types don't get their own pages, but they should be kept track of in the reflection resolving stages, so while the inheritance tree is understandable, it's very confusing why we're not even seeing the inherited members.

interface Foo {
    one: number;
    two: number;
}

export type FooPicked = Pick<Foo, 'one'>;
export interface Bar extends FooPicked {
    three: string;
}

Screen Shot 2020-10-29 at 10 44 10 AM

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Oct 31, 2020

The library mode support for inheritance is being tracked in #1386, I'll be looking at that next week, and hopefully end up with something that produces reasonable results. I'm pretty sure TypeDoc's inheritance support was written before you could inherit from types, so it was never considered.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Nov 28, 2020

This works properly in 0.20 - took a bit more than a week.. but worth the time spent understanding it all.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Functionality does not match expectation
Projects
None yet
Development

No branches or pull requests

5 participants