Skip to content

Commit

Permalink
feat(vscode): support template literal types
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsdev committed Oct 12, 2022
1 parent 835bfd5 commit 36b4edf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/api/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function multilineTypeToString(typeChecker: ts.TypeChecker, sourceFile: t

export function wrapSafe<T, Args extends Array<any>, Return>(wrapped: (arg1: T, ...args: Args) => Return): (arg1: T|undefined, ...args: Args) => Return|undefined {
return (arg1, ...args) => arg1 === undefined ? arg1 as undefined : wrapped(arg1, ...args)
}
}

export function getTypeId(type: ts.Type) {
return (type as ts.Type & {id: number}).id
Expand Down
29 changes: 29 additions & 0 deletions packages/typescript-explorer/src/view/typeTreeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,34 @@ class TypeNode extends TypeTreeItem {
return [toTreeNode(type)]
}

case "template_literal": {
const { types, texts } = this.typeTree
const res: TypeTreeItem[] = []

let i = 0, j = 0

while(i < texts.length || j < types.length) {
if(i < texts.length) {
const text = texts[i]
if(text) {
// TODO: this should probably be its own treenode type
res.push(
toTreeNode({ kind: 'string_literal', id: -1, value: text })
)
}
i++
}

if(j < types.length) {
const type = types[j]
res.push(toTreeNode(type))
j++
}
}

return res
}

case "primitive":
case "bigint_literal":
case "boolean_literal":
Expand Down Expand Up @@ -359,4 +387,5 @@ function kindHasChildren(kind: TypeInfoKind) {
|| kind === 'tuple'
|| kind === 'function'
|| kind === 'string_mapping'
|| kind === 'template_literal'
}

0 comments on commit 36b4edf

Please sign in to comment.