denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
96.3k stars 5.32k forks source link

'deno doc --lint' nondeterministically reports spurious 'private type' errors #25188

Open skybrian opened 1 month ago

skybrian commented 1 month ago

Version: Deno 1.46.2

To reproduce:

git clone https://github.com/skybrian/repeat-test
cd repeat-test
git reset --hard c4cb924c9c97230fabea945793ac03fa149545d2
deno doc --lint domain.ts

Sometimes it reports no errors, but other times it does. Here's is example output when it reports errors:

error[private-type-ref]: public type 'Domain' references private type 'Arbitrary'
  --> /Users/skybrian/Projects/tmp/repeat-test/src/domain_class.ts:48:1
   | 
48 | export class Domain<T> extends Arbitrary<T> {
   | ^
   = hint: make the referenced type public or remove the reference
   | 
33 | export class Arbitrary<T> implements PickSet<T> {
   | - this is the referenced type
   | 

  info: to ensure documentation is complete all types that are exposed in the public API must be public

error[private-type-ref]: public type 'Domain.prototype.regenerate' references private type 'Generated'
   --> /Users/skybrian/Projects/tmp/repeat-test/src/domain_class.ts:122:3
    | 
122 |   regenerate(val: unknown): Generated<T> | Failure {
    |   ^
    = hint: make the referenced type public or remove the reference
    | 
122 | export type Generated<T> = {
    | - this is the referenced type
    | 

  info: to ensure documentation is complete all types that are exposed in the public API must be public

error[private-type-ref]: public type 'Jar.prototype.take' references private type 'PickFunction'
  --> /Users/skybrian/Projects/tmp/repeat-test/src/jar_class.ts:54:3
   | 
54 |   take(pick: PickFunction): T {
   |   ^
   = hint: make the referenced type public or remove the reference
   | 
45 | export interface PickFunction {
   | - this is the referenced type
   | 

  info: to ensure documentation is complete all types that are exposed in the public API must be public

error: Found 3 documentation lint errors.
skybrian commented 1 month ago

I don't know if this is the right way, but I worked around this by putting all my entrypoints in a subdirectory and checking them at once:

deno doc --lint ./src/entrypoints/*.ts

Or at least, I don't seem to be getting any errors that way.

5ouma commented 1 month ago

https://github.com/denoland/deno/issues/25188#issuecomment-2318498834

Thanks to @dsherret, it's solved.

I have the same issue. When I run `deno doc --lint main.ts` with this TS file, it says this. ```ts import type { UserAgent } from "jsr:@std/http/user-agent"; /** * This function causes an error * * @param userAgent Why this is not detected */ export function foo(userAgent: UserAgent) { console.log(userAgent); } ``` ``` error[private-type-ref]: public type 'foo' references private type 'UserAgent' --> /Users/5ouma/Temp/main.ts:8:1 | 8 | export function foo(userAgent: UserAgent) { | ^ = hint: make the referenced type public or remove the reference | 982 | export class UserAgent { | - this is the referenced type | info: to ensure documentation is complete all types that are exposed in the public API must be public error: Found 1 documentation lint error. ```

dsherret commented 1 month ago

@5ouma that doesn't seem like a bug. The code needs to export the UserAgent type because it's used in the public api of foo:

export type { UserAgent } from "jsr:@std/http/user-agent";

In the future we'll add a way to disable these errors if you don't want to do that. (I think currently the only way to do it is to create an intermediary type and mark it as internal:

// something like this
/** @internal */
type UserAgent = import("jsr:@std/http/user-agent").UserAgent;
dsherret commented 1 month ago

I'm able to reproduce the original issue. Strange.