fix(types): correct intersection, indexedAccess, and add predicate/templateLiteral#66
fix(types): correct intersection, indexedAccess, and add predicate/templateLiteral#66sujalgoel wants to merge 3 commits intowebpack:mainfrom
Conversation
…mplateLiteral
- `intersection` was using `|` separator (same as union); now correctly uses `&`
- e.g. `A & B` previously rendered as `{A|B}`, now `{A&B}`
- `indexedAccess` and `optional` were merged under one case using
`type.elementType ?? type.objectType`; `IndexedAccessType` has no
`elementType` field, so the fallback always lost the index type entirely
- e.g. `T[K]` previously rendered as `{T}`, now `{T[K]}`
- Add `predicate` case for type predicate signatures (`x is T`,
`asserts x is T`)
- Add `templateLiteral` case for template literal types
(e.g. `` `prefix_${string}` ``)
avivkeller
left a comment
There was a problem hiding this comment.
doc-kit doesn't yet support this. Please very that before sending a PR
|
Checked this against doc-kit's
The other three are fine: Neither Happy to either drop |
|
Just because the normalizing regex matches the content of the {...}, doesn't mean they will be properly mapped to types. |
plugins/theme/partials/types.mjs
Outdated
| case 'predicate': { | ||
| const target = type.targetType ? ` is ${resolve(type.targetType)}` : ''; | ||
| return (type.asserts ? 'asserts ' : '') + type.name + target; | ||
| } |
There was a problem hiding this comment.
We should just return the target, perhaps
plugins/theme/partials/types.mjs
Outdated
| case 'templateLiteral': | ||
| return ( | ||
| '`' + | ||
| type.head + | ||
| type.tail.map(([t, s]) => '${' + resolve(t) + '}' + s).join('') + | ||
| '`' | ||
| ); |
|
Got it. The theme fix needs doc-kit to support |
Per review feedback: - predicate: return resolve(type.targetType) instead of full predicate syntax - templateLiteral: reverted, doc-kit does not yet support this
|
Neither, if you'd like to open a PR to doc-kit, please do. A tracking issue isn't really needed, since it's more of a QoL thing |
Problem
Four bugs in
plugins/theme/partials/types.mjs:1.
intersectionrendered with|instead of&The
unionandintersectioncases shared onereturn union(type.types)call.union()defaults to|, soA & Bwas rendered as{A|B}— same as a union type.2.
indexedAccesslost the index typeoptionalandindexedAccesswere merged under one case usingtype.elementType ?? type.objectType.IndexedAccessTypehas noelementTypefield, so the fallback always resolved toobjectTypealone — dropping the index type entirely.T[K]was rendered as{T}, now renders as{T[K]}3. Missing
predicatecaseTypeDoc emits
predicatetypes for type guard signatures likex is stringandasserts x is string. These fell through to thedefaultbranch and returnedtype.name ?? 'unknown'— dropping the target type.4. Missing
templateLiteralcaseTemplate literal types (
`prefix_${string}`) also fell through to thedefaultbranch.Fix
unionandintersectioninto separate cases;intersectionpasses'&'as the separatoroptionalandindexedAccessinto separate cases;indexedAccessrenders asobjectType[indexType]predicatecase:(asserts?) name (is targetType?)templateLiteralcase:`head${type1}span1${type2}span2...`Verification
Pipeline (
node generate-md.mjs) runs clean. Spot-checked output: