`deno doc` doesn't infer types from object literal
Example
https://deno.land/x/[email protected]/protocol/reply.ts contains the following definition:
export const replyTypes = {
Integer: "integer",
SimpleString: "simple string",
Array: "array",
BulkString: "bulk string",
} as const;
deno doc generates the following output for the above file:
$ deno doc https://deno.land/x/[email protected]/protocol/reply.ts replyTypes
Defined in https://deno.land/x/[email protected]/protocol/reply.ts:12:0
const replyTypes
I think deno doc should output type of the replyTypes variable, but outputs nothing.
Environment
- deno v1.8.2
This isn't a defect, it is either a current design limitation and/or feature request, as we do not type inference (e.g. inferred return types, or in this case, object literals. We only document specified type annotations.
Correction, we do infer some trivial types for const variables, just not more complex types like object literals.
As mentioned in #113, we should also ensure that when we infer types for an object literal, we infer the associated JSDoc block.
Posting another example from Deno source.
JSDoc is stripped for methods in object literals.
Type Definitions for Deno.env from lib.deno.ns.d.ts
export const env: {
/** Retrieve the value of an environment variable. Returns `undefined` if that
* key doesn't exist.
*
* ```ts
* console.log(Deno.env.get("HOME")); // e.g. outputs "/home/alice"
* console.log(Deno.env.get("MADE_UP_VAR")); // outputs "undefined"
* ```
* Requires `allow-env` permission. */
get(key: string): string | undefined;
/** Set the value of an environment variable.
*
* ```ts
* Deno.env.set("SOME_VAR", "Value");
* Deno.env.get("SOME_VAR"); // outputs "Value"
* ```
*
* Requires `allow-env` permission. */
set(key: string, value: string): void;
/** Delete the value of an environment variable.
*
* ```ts
* Deno.env.set("SOME_VAR", "Value");
* Deno.env.delete("SOME_VAR"); // outputs "undefined"
* ```
*
* Requires `allow-env` permission. */
delete(key: string): void;
/** Returns a snapshot of the environment variables at invocation.
*
* ```ts
* Deno.env.set("TEST_VAR", "A");
* const myEnv = Deno.env.toObject();
* console.log(myEnv.SHELL);
* Deno.env.set("TEST_VAR", "B");
* console.log(myEnv.TEST_VAR); // outputs "A"
* ```
*
* Requires `allow-env` permission. */
toObject(): { [index: string]: string };
};
Rendered: