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

issues about #2479 #2503

Closed
steve02081504 opened this issue Feb 15, 2024 · 6 comments
Closed

issues about #2479 #2503

steve02081504 opened this issue Feb 15, 2024 · 6 comments
Labels
bug Functionality does not match expectation

Comments

@steve02081504
Copy link
Contributor

steve02081504 commented Feb 15, 2024

Search terms

marge

Behavior

I tried updating the d.ts file of jsstp to try the new features added in 0.25.8 about #2479, and it looks like there are still some details that may need to be fixed
https://ukatech.github.io/jsstp-lib/doc/EN/classes/ghost_events_queryer_t.html

  1. Duplicate constructors
    Somehow there are two constructor declarations for this type, even though they have exactly the same content
    https://ukatech.github.io/jsstp-lib/doc/EN/classes/ghost_events_queryer_t.html#constructor
  2. The call operator is not recorded on the page
    It looks like when there is a variable and a type with the same name that both is marked as class, Typedoc will only use the variable to generate the page, and I prefer it to reference the type or both.
  3. Inherited members are not marked as Inherited
    Members inherited from the ExtensibleFunction type are not marked as inherited.

Steps to reproduce the bug

code: https://github.com/ukatech/jsstp-lib/tree/b94087beefedae3f52d46644718bbd12eb1aba10/src/.decls/en

Environment

  • Typedoc version: ^0.25.8
  • TypeScript version: idk
  • Node.js version: latest
  • OS: ubuntu-latest
@steve02081504 steve02081504 added the bug Functionality does not match expectation label Feb 15, 2024
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Feb 15, 2024

Please provide minimal reproductions of problems. I don't have time to spend hunting through your project to extract them and get rid of the unnecessary noise.

@steve02081504
Copy link
Contributor Author

steve02081504 commented Feb 16, 2024

Please provide minimal reproductions of problems. I don't have time to spend hunting through your project to extract them and get rid of the unnecessary noise.

declare class base{
	not_markdas_Inherited: Number;
}

declare class class_impl extends base {
	constructor(a: Number);//double constructors1
}
type call_signature = {
	(a: Number): Number;//not in doc of my_class
}
type constructor_impl = {
	new(a: Number): my_class;//double constructors2
}
/**
 * @class
 */
declare const my_class: typeof class_impl & constructor_impl;
/**
 * @class
 */
type my_class= class_impl & call_signature & {
	constructor: typeof my_class;
}

this may work

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Feb 18, 2024

  1. Duplicate constructors - This is working as intended. TypeDoc is accurately representing that your class type does have two construct signatures. If you want to hide one of them, you can do this with /** @hidden */ on either the constructor declaration, or the constructor_impl's new declaration.

  2. Call signature - This is a design limitation. TypeDoc uses the first constructor signature to determine what the type of the class is. Because you declared my_class as typeof class_impl & ..., the constructor signature on your implementation class was used, which does not have a call signature. If you swapped the order of the intersection, TypeDoc would include the call signature. (Note: Using @hidden on the class's constructor doesn't prevent TypeDoc from using it to determine the type here)

  3. Inheritance only works for real classes. If you look at the docs for class_impl, you'll see that inheritance works as expected there. With my_class, there is no extends clause to look at to determine what the base classes are. I'm going to consider this a design limitation as well.

Typedoc will only use the variable to generate the page, and I prefer it to reference the type or both.

Yes, that's correct. I very intentionally decided to use the variable here, because that's what users will deal with. If that type isn't correct, they're going to have a bad time trying to use your types to work with real values. I have no plans to change this.

With the example you've provided, I'd strongly recommend using a real class declaration with declaration merging in your types instead of this jumble of intersections.

export interface my_class {
    constructor: typeof my_class;
    (a: number): number;
}
export declare class my_class extends base {
    constructor(a: number);
}

(Also, sidenote, don't use Number as a type. That refers to an instance of the Number class, as in new Number(123) rather than a number literal TS docs)

@steve02081504
Copy link
Contributor Author

steve02081504 commented Feb 19, 2024

@Gerrit0 Thank you for your help! I tried using the code you provided, or swapping the order of intersection operations, but the call signature never appears in the documentation
I'm not sure what I'm not doing right
code 1:

declare class my_class extends base {
    constructor(a: number);
}
interface my_class {
    constructor: typeof my_class;
    (a: number): number;
}
export default my_class;

code 2:

//same as above....
type my_class= call_signature & class_impl & { // swaped!
	constructor: typeof my_class;
}

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Feb 23, 2024

I copied your "code 1" into a new file, added an empty class base {}, and ran typedoc, the signature is displayed at the top of the class's page (before the index)

In "code 2" -- TypeDoc doesn't use types when converting a variable as a class, you need to swap the order in the variable declaration.

declare const my_class: constructor_impl & typeof class_impl;

steve02081504 added a commit to ukatech/jsstp-lib that referenced this issue Feb 23, 2024
@steve02081504
Copy link
Contributor Author

Sorry it looks like I misread it before.
Thanks for clearing that up and have a nice day!

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

2 participants