-
-
Notifications
You must be signed in to change notification settings - Fork 745
Description
Problem
When TypeDoc generates documentation in JSON, bumping into complex object/template literal types, it takes them apart piece by piece, instead of creating a reference type.
Actual Behavior
TypeDoc creates a huge union type, parsing type alias into all its possible values:
At the same time, the type to which it should refer is declared correctly and exported:
And this type declaration works file:
"type": {
"type": "template-literal",
"head": "",
"tail": [
[
{
"type": "query",
"queryType": {
"type": "reference",
"id": 5940,
"name": "CACHE_POINTER_PREFIX"
}
},
":"
],
[
{
"type": "reference",
"id": 5950,
"name": "Keyspaces"
},
":"
],
[
{
"type": "reference",
"qualifiedName": "CacheStorageKey",
"package": "@discordoo/providers",
"name": "CacheStorageKey"
},
":"
],
[
{
"type": "intrinsic",
"name": "string"
},
""
]
]
}
As a result, the documentation looks like this:
Expected Behavior
But the documentation is expected to look like this:
TypeDoc was expected to create a reference to the type:
"type": {
"type": "union",
"types": [
{
"type": "reference",
"id": 4869,
"name": "CachePointer"
},
{
"type": "reference",
"id": 4681,
"name": "V"
}
]
}
Steps to reproduce the bug
Reproduction repo: https://github.com/Mirdukkk/typedoc-issue
- Create any complex type, such as an object:
// types.ts
const something = 'something'
export const SOME_CONST = {
valuenum1: something,
valuenum2: something,
valuenum3: something,
valuenum4: something,
valuenum5: something,
valuenum6: something,
valuenum7: something,
valuenum8: something,
valuenum9: something,
valuenum10: something,
valuenum11: something,
}
export type SomeConstType = typeof SOME_CONST // this type will cause problem
- Use it in absolutely any place where Type Doc can document it:
// work.ts
import { SomeConstType, SOME_CONST } from './types'
export function doSomething<K extends keyof SomeConstType>(key: K): SomeConstType[K] {
return SOME_CONST[key]
}
- Don't forget to export it all so that typedoc has the opportunity to document it:
// index.ts
export { SomeConstType } from './types'
export { doSomething } from './work'
- Document it with json output:
npx typedoc index.ts --json docs.json
- You will see that in the declaration of the return type of the doSomething function, there is a huge union type, instead of the reference type.
Don't forget to put any tsconfig that would compile three files: index.ts, work.ts and types.ts.
See also
perhaps the bug reason is here: #1258 (comment)
Environment
- Typedoc version: 0.22.11
- TypeScript version: 4.5.5
- Node.js version: tested on 12.20.0/16.6.0/17.1.0 with the same result
- OS: Win32 19043.1415 / Linux 4.4.0-19041-Microsoft 1237-Microsoft Sat Sep 11 14:32:00 PST 2021 x86_64 x86_64 x86_64 GNU/Linux (Windows WSL Ubuntu 20.04)
Search terms
type aliases
expands
reffer