Skip to content

🐛 Implementation of overloaded function needs @public tag inside namespace, not outside. #1639

@Jym77

Description

@Jym77

Prerequisites

Reproduction url

https://github.com/Jym77/knip-namespace-overload

Reproduction access

  • I've made sure the reproduction is publicly accessible

Description of the issue

Sorry, one more for the namespaces 😅

foo.ts:

/** @public */
export function hello(x: number): number

/** @public */
export function hello(x: string): number

export function hello(x: number | string): number {
  return 1;
}

export namespace Foo {
  /** @public */
  export function hello(x: number): number

  /** @public */
  export function hello(x: string): number

  export function hello(x: number | string): number {
    return 1;
  }
}

index.ts

import { Foo } from './foo.ts'

So, none of the functions are used, but the @public tag tells knip that it's OK. Running knip results in:

Unused exported namespace members (1)
hello  Foo  foo.ts:18:19

which reports the implementation of Foo.hello (not its overloads, who are @public). Adding a @public tag to the implementation removes the flagging.

Where it is weird, is that the (top-level) hello is exactly the same code, and there the implementation without the @public tag is not reported.

I think the top-level behaviour makes sense: only the overloads are really making it to the API of the package, the implementation signature is hidden for users. (and different overloads could actually have different release tags).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions