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

Function with properties shown as variable #1651

Closed
y-nk opened this issue Aug 11, 2021 · 4 comments
Closed

Function with properties shown as variable #1651

y-nk opened this issue Aug 11, 2021 · 4 comments
Labels
enhancement Improved functionality

Comments

@y-nk
Copy link

y-nk commented Aug 11, 2021

Search terms

Functions type property

Expected Behavior

Functions should be listed as functions

Actual Behavior

Steps to reproduce the bug

// will be seen as function in typedoc
const foo = () => {}

// will be seen as variable in typedoc
const bar = () => {}
bar.metadata = "baz"

Environment

  • Typedoc version: latest
  • TypeScript version: latest
@y-nk y-nk added the bug Functionality does not match expectation label Aug 11, 2021
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Aug 13, 2021

This happens because it isn't caught as a special case in the converter

if (type.getCallSignatures().length && !type.getProperties().length) {
return convertVariableAsFunction(context, symbol, exportSymbol);
}

Fixing it would involve updating that to also create a namespace for any properties.

Workaround:

const bar = () => {}
namespace bar {
  export const metadata = "baz"
}

@Gerrit0 Gerrit0 added enhancement Improved functionality and removed bug Functionality does not match expectation labels Oct 3, 2021
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Oct 18, 2021

Note: Should probably do this only if the extra properties are defined with a PropertyAccessExpression. It would make #1735 worse to do it in every case.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jul 1, 2022

Apparently some TS version changed how symbol flags were set, because in TS 4.7.2, with no code changes, the following gets converted as a variable and a namespace.

const bar = () => {}
bar.metadata = "baz"

I'm going to go ahead and make the change to convert a variable as a function if it contains any call signatures... hopefully it doesn't make worse documentation in some edge case I'm not thinking of right now.

@Gerrit0 Gerrit0 closed this as completed in e74eea6 Jul 1, 2022
@y-nk
Copy link
Author

y-nk commented Jul 7, 2022

@Gerrit0 thank you for the long-term follow-up this is highly appreciated. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improved functionality
Projects
None yet
Development

No branches or pull requests

2 participants