diff --git a/src/models/node.ts b/src/models/node.ts index 787adb7..7e5ec35 100644 --- a/src/models/node.ts +++ b/src/models/node.ts @@ -1,5 +1,5 @@ export interface TypeNode { readonly kind: string; name: string | undefined; - parentNamespaces: string[]; + parentNamespaces: string[] | undefined; } diff --git a/src/models/types/intersection.ts b/src/models/types/intersection.ts index 1fa759b..532f189 100644 --- a/src/models/types/intersection.ts +++ b/src/models/types/intersection.ts @@ -7,14 +7,16 @@ export class IntersectionNode implements TypeNode { constructor( public name: string | undefined, - public parentNamespaces: string[], + parentNamespaces: string[], types: TypeNode[], public properties: PropertyNode[], ) { const flatTypes = flattenTypes(types, IntersectionNode); sortMemberTypes(flatTypes); this.types = deduplicateMemberTypes(flatTypes); + this.parentNamespaces = name ? parentNamespaces : undefined; } types: readonly TypeNode[]; + parentNamespaces: string[] | undefined; } diff --git a/src/models/types/union.ts b/src/models/types/union.ts index d338f5c..b4a7851 100644 --- a/src/models/types/union.ts +++ b/src/models/types/union.ts @@ -8,16 +8,18 @@ export class UnionNode implements TypeNode { constructor( public name: string | undefined, - public parentNamespaces: string[], + parentNamespaces: string[], types: TypeNode[], ) { const flatTypes = flattenTypes(types, UnionNode); sanitizeBooleanLiterals(flatTypes); sortMemberTypes(flatTypes); this.types = deduplicateMemberTypes(flatTypes); + this.parentNamespaces = name ? parentNamespaces : undefined; } types: readonly TypeNode[]; + parentNamespaces: string[] | undefined; } /** diff --git a/src/parsers/exportParser.ts b/src/parsers/exportParser.ts index 84ff402..c375daa 100644 --- a/src/parsers/exportParser.ts +++ b/src/parsers/exportParser.ts @@ -149,7 +149,7 @@ export function parseExport( type: ts.Type, parentNamespaces: string[], ) { - const parsedType = resolveType(type, symbol.getName(), parserContext); + const parsedType = resolveType(type, parserContext); if (parsedType) { // Patch parentNamespaces if the type supports it if (parsedType && 'parentNamespaces' in parsedType) { diff --git a/src/parsers/functionParser.ts b/src/parsers/functionParser.ts index 0aaea98..29ce149 100644 --- a/src/parsers/functionParser.ts +++ b/src/parsers/functionParser.ts @@ -75,11 +75,7 @@ function parseFunctionSignature( parseParameter(parameterSymbol, context, skipResolvingComplexTypes), ); - const returnValueType = resolveType( - signature.getReturnType(), - signature.getDeclaration().name?.getText() || '', - context, - ); + const returnValueType = resolveType(signature.getReturnType(), context); return new CallSignature(parameters, returnValueType); } @@ -94,10 +90,11 @@ function parseParameter( try { const parameterDeclaration = parameterSymbol.valueDeclaration as ts.ParameterDeclaration; + const parameterType = resolveType( checker.getTypeOfSymbolAtLocation(parameterSymbol, parameterSymbol.valueDeclaration!), - parameterSymbol.getName(), context, + parameterDeclaration.type, skipResolvingComplexTypes, ); diff --git a/src/parsers/objectParser.ts b/src/parsers/objectParser.ts index 597320a..2fafdf2 100644 --- a/src/parsers/objectParser.ts +++ b/src/parsers/objectParser.ts @@ -2,32 +2,31 @@ import ts from 'typescript'; import { parseProperty } from './propertyParser'; import { ParserContext } from '../parser'; import { ObjectNode } from '../models'; -import { getTypeNamespaces } from './typeResolver'; +import { getTypeName, getTypeNamespaces } from './typeResolver'; export function parseObjectType( type: ts.Type, - name: string, context: ParserContext, skipResolvingComplexTypes: boolean, ): ObjectNode | undefined { - const { shouldInclude, shouldResolveObject, typeStack, includeExternalTypes } = context; + const { shouldInclude, shouldResolveObject, typeStack, includeExternalTypes, checker } = context; const properties = type .getProperties() .filter((property) => includeExternalTypes || !isPropertyExternal(property)); - const typeSymbol = type.aliasSymbol ?? type.getSymbol(); - let typeName = typeSymbol?.getName(); - if (typeName === '__type') { - typeName = undefined; - } + const typeName = getTypeName(type, undefined, checker, false); if (properties.length) { if ( !skipResolvingComplexTypes && - shouldResolveObject({ name, propertyCount: properties.length, depth: typeStack.length }) + shouldResolveObject({ + name: typeName ?? '', + propertyCount: properties.length, + depth: typeStack.length, + }) ) { - const filtered = properties.filter((property) => { + const filteredProperties = properties.filter((property) => { const declaration = property.valueDeclaration ?? (property.declarations?.[0] as ts.PropertySignature | undefined); @@ -37,11 +36,11 @@ export function parseObjectType( shouldInclude({ name: property.getName(), depth: typeStack.length + 1 }) ); }); - if (filtered.length > 0) { + if (filteredProperties.length > 0) { return new ObjectNode( typeName, getTypeNamespaces(type), - filtered.map((property) => { + filteredProperties.map((property) => { return parseProperty( property, property.valueDeclaration as ts.PropertySignature, diff --git a/src/parsers/propertyParser.ts b/src/parsers/propertyParser.ts index 6d2b2c2..75085da 100644 --- a/src/parsers/propertyParser.ts +++ b/src/parsers/propertyParser.ts @@ -16,11 +16,12 @@ export function parseProperty( try { let type: ts.Type; + if (propertySignature) { - if (!propertySignature.type) { - type = checker.getAnyType(); - } else { + if (propertySignature.type) { type = checker.getTypeOfSymbolAtLocation(propertySymbol, propertySignature.type); + } else { + type = checker.getAnyType(); } } else { type = checker.getTypeOfSymbol(propertySymbol); @@ -36,7 +37,12 @@ export function parseProperty( parsedType = new IntrinsicNode('any'); isOptional = Boolean(propertySignature.questionToken); } else { - parsedType = resolveType(type, propertySymbol.getName(), context, skipResolvingComplexTypes); + parsedType = resolveType( + type, + context, + isTypeParameterLike(type) ? undefined : propertySignature?.type, + skipResolvingComplexTypes, + ); isOptional = Boolean(propertySymbol.flags & ts.SymbolFlags.Optional); } @@ -58,3 +64,25 @@ export function parseProperty( parsedSymbolStack.pop(); } } + +function isTypeParameterLike(type: ts.Type): boolean { + // Check if the type is a type parameter + return ( + (type.flags & ts.TypeFlags.TypeParameter) !== 0 || + ((type.flags & ts.TypeFlags.Union) !== 0 && isOptionalTypeParameter(type as ts.UnionType)) + ); +} + +function isOptionalTypeParameter(type: ts.UnionType): boolean { + // Check if the type is defined as + // foo?: T + // where T is a type parameter + + return ( + type.types.length === 2 && + type.types.some((t) => t.flags & ts.TypeFlags.Undefined) && + type.types.some( + (t) => 'objectFlags' in t && ((t.objectFlags as number) & ts.ObjectFlags.Instantiated) !== 0, + ) + ); +} diff --git a/src/parsers/typeResolver.ts b/src/parsers/typeResolver.ts index 15036a5..97a8d86 100644 --- a/src/parsers/typeResolver.ts +++ b/src/parsers/typeResolver.ts @@ -19,8 +19,8 @@ import { export function resolveType( type: ts.Type, - name: string, context: ParserContext, + typeNode?: ts.TypeNode, skipResolvingComplexTypes: boolean = false, ): TypeNode { const { checker, typeStack, includeExternalTypes } = context; @@ -37,7 +37,31 @@ export function resolveType( typeStack.push(typeId); } - const namespaces = getTypeNamespaces(type); + // The following code handles cases where the type is a simple alias of another type (type Alias = SomeType). + // TypeScript resolves the alias automatically, but we want to preserve the original type symbol if it exists. + // + // However, this also covers cases where the type is a type parameter (as in `type Generic = { value: T }`). + // Here we don't want to preserve T as a type symbol, but rather resolve it to its actual type. + let typeSymbol: ts.Symbol | undefined; + if (typeNode && ts.isTypeReferenceNode(typeNode)) { + const typeNodeName = (typeNode as ts.TypeReferenceNode).typeName; + if (ts.isIdentifier(typeNodeName) && typeNodeName.text !== type.aliasSymbol?.name) { + const typeSymbolCandidate = checker.getSymbolAtLocation(typeNodeName); + if (typeSymbolCandidate && !(typeSymbolCandidate.flags & ts.SymbolFlags.TypeParameter)) { + typeSymbol = typeSymbolCandidate; + } + } else if ( + ts.isQualifiedName(typeNodeName) && + typeNodeName.right.text !== type.aliasSymbol?.name + ) { + const typeSymbolCandidate = checker.getSymbolAtLocation(typeNodeName.right); + if (typeSymbolCandidate && !(typeSymbolCandidate.flags & ts.SymbolFlags.TypeParameter)) { + typeSymbol = typeSymbolCandidate; + } + } + } + + const namespaces = typeSymbol ? getTypeSymbolNamespaces(typeSymbol) : getTypeNamespaces(type); try { if (type.flags & ts.TypeFlags.TypeParameter && type.symbol) { @@ -47,7 +71,7 @@ export function resolveType( namespaces, declaration?.constraint?.getText(), declaration?.default - ? resolveType(checker.getTypeAtLocation(declaration.default), '', context) + ? resolveType(checker.getTypeAtLocation(declaration.default), context) : undefined, ); } @@ -55,21 +79,17 @@ export function resolveType( if (checker.isArrayType(type)) { // @ts-expect-error - Private method const arrayType: ts.Type = checker.getElementTypeOfArrayType(type); - return new ArrayNode( - type.aliasSymbol?.name, - namespaces, - resolveType(arrayType, name, context), - ); + return new ArrayNode(type.aliasSymbol?.name, namespaces, resolveType(arrayType, context)); } if (!includeExternalTypes && isTypeExternal(type, checker)) { - const typeName = getTypeName(type, checker); + const typeName = getTypeName(type, typeSymbol, checker); // Fixes a weird TS behavior where it doesn't show the alias name but resolves to the actual type in case of RefCallback. if (typeName === 'bivarianceHack') { return new ReferenceNode('RefCallback', []); } - return new ReferenceNode(getTypeName(type, checker), namespaces); + return new ReferenceNode(typeName ?? checker.typeToString(type), namespaces); } if (hasFlag(type.flags, ts.TypeFlags.Boolean)) { @@ -96,21 +116,17 @@ export function resolveType( if (type.isUnion()) { const memberTypes: TypeNode[] = []; - const symbol = type.aliasSymbol ?? type.getSymbol(); - let typeName = symbol?.getName(); - if (typeName === '__type') { - typeName = undefined; - } + const typeName = getTypeName(type, typeSymbol, checker, false); // @ts-expect-error - Internal API if (type.origin?.isUnion()) { // @ts-expect-error - Internal API for (const memberType of type.origin.types) { - memberTypes.push(resolveType(memberType, memberType.getSymbol()?.name || '', context)); + memberTypes.push(resolveType(memberType, context)); } } else { for (const memberType of type.types) { - memberTypes.push(resolveType(memberType, memberType.getSymbol()?.name || '', context)); + memberTypes.push(resolveType(memberType, context)); } } @@ -121,14 +137,10 @@ export function resolveType( if (type.isIntersection()) { const memberTypes: TypeNode[] = []; - const symbol = type.aliasSymbol ?? type.getSymbol(); - let typeName = symbol?.getName(); - if (typeName === '__type') { - typeName = undefined; - } + const typeName = getTypeName(type, typeSymbol, checker, false); for (const memberType of type.types) { - memberTypes.push(resolveType(memberType, memberType.getSymbol()?.name || '', context)); + memberTypes.push(resolveType(memberType, context)); } if (memberTypes.length === 0) { @@ -149,7 +161,7 @@ export function resolveType( return parseFunctionType(type, context)!; } - const objectType = parseObjectType(type, name, context, skipResolvingComplexTypes); + const objectType = parseObjectType(type, context, skipResolvingComplexTypes); if (objectType) { return new IntersectionNode(typeName, namespaces, memberTypes, objectType.properties); } @@ -160,11 +172,9 @@ export function resolveType( if (checker.isTupleType(type)) { return new TupleNode( - undefined, + typeSymbol?.name ?? type.aliasSymbol?.name, [], - (type as ts.TupleType).typeArguments?.map((x) => - resolveType(x, x.getSymbol()?.name || '', context), - ) ?? [], + (type as ts.TupleType).typeArguments?.map((x) => resolveType(x, context)) ?? [], ); } @@ -218,7 +228,7 @@ export function resolveType( return parseFunctionType(type, context)!; } - const objectType = parseObjectType(type, name, context, skipResolvingComplexTypes); + const objectType = parseObjectType(type, context, skipResolvingComplexTypes); if (objectType) { return objectType; } @@ -228,12 +238,7 @@ export function resolveType( type.flags & ts.TypeFlags.Object || (type.flags & ts.TypeFlags.NonPrimitive && checker.typeToString(type) === 'object') ) { - const typeSymbol = type.aliasSymbol ?? type.getSymbol(); - let typeName = typeSymbol?.getName(); - if (typeName === '__type') { - typeName = undefined; - } - + const typeName = getTypeName(type, typeSymbol, checker, false); return new ObjectNode(typeName, namespaces, [], undefined); } @@ -244,14 +249,14 @@ export function resolveType( undefined, [], [ - resolveType((type as ts.ConditionalType).resolvedTrueType!, '', context), - resolveType((type as ts.ConditionalType).resolvedFalseType!, '', context), + resolveType((type as ts.ConditionalType).resolvedTrueType!, context), + resolveType((type as ts.ConditionalType).resolvedFalseType!, context), ], ); } else if (conditionalType.resolvedTrueType) { - return resolveType(conditionalType.resolvedTrueType, '', context); + return resolveType(conditionalType.resolvedTrueType, context); } else if (conditionalType.resolvedFalseType) { - return resolveType(conditionalType.resolvedFalseType, '', context); + return resolveType(conditionalType.resolvedFalseType, context); } } @@ -291,24 +296,31 @@ export function getTypeNamespaces(type: ts.Type): string[] { return []; } - if (symbol.name === '__function' || symbol.name === '__type') { + return getTypeSymbolNamespaces(symbol); +} + +function getTypeSymbolNamespaces(typeSymbol: ts.Symbol): string[] { + if (typeSymbol.name === '__function' || typeSymbol.name === '__type') { return []; } - const declaration = symbol.valueDeclaration ?? symbol.declarations?.[0]; - if (!declaration) { + const declaration = typeSymbol.valueDeclaration ?? typeSymbol.declarations?.[0]; + return getNodeNamespaces(declaration); +} +export function getNodeNamespaces(node: ts.Node | undefined): string[] { + if (!node) { return []; } const namespaces: string[] = []; - let currentDeclaration: ts.Node = declaration.parent; + let currentNode = node.parent; - while (currentDeclaration != null && !ts.isSourceFile(currentDeclaration)) { - if (ts.isModuleDeclaration(currentDeclaration)) { - namespaces.unshift(currentDeclaration.name.getText()); + while (currentNode != null && !ts.isSourceFile(currentNode)) { + if (ts.isModuleDeclaration(currentNode)) { + namespaces.unshift(currentNode.name.getText()); } - currentDeclaration = currentDeclaration.parent; + currentNode = currentNode.parent; } return namespaces; @@ -333,26 +345,43 @@ function isTypeExternal(type: ts.Type, checker: ts.TypeChecker): boolean { ); } -function getTypeName(type: ts.Type, checker: ts.TypeChecker): string { - const symbol = type.aliasSymbol ?? type.getSymbol(); +export function getTypeName( + type: ts.Type, + typeSymbol: ts.Symbol | undefined, + checker: ts.TypeChecker, + useFallback: boolean = true, +): string | undefined { + const symbol = typeSymbol ?? type.aliasSymbol ?? type.getSymbol(); if (!symbol) { - return checker.typeToString(type); + return useFallback ? checker.typeToString(type) : undefined; + } + + if (typeSymbol && !type.aliasSymbol && !type.symbol) { + return useFallback ? checker.typeToString(type) : undefined; } const typeName = symbol.getName(); if (typeName === '__type') { - return checker.typeToString(type); + return useFallback ? checker.typeToString(type) : undefined; } let typeArguments: string[] | undefined; - if ('target' in type) { - typeArguments = checker - .getTypeArguments(type as ts.TypeReference) - ?.map((x) => getTypeName(x, checker)); - } - if (!typeArguments?.length) { - typeArguments = type.aliasTypeArguments?.map((x) => getTypeName(x, checker)) ?? []; + if (type.aliasSymbol && !type.aliasTypeArguments) { + typeArguments = []; + } else { + if ('target' in type) { + typeArguments = checker + .getTypeArguments(type as ts.TypeReference) + ?.map((x) => getTypeName(x, undefined, checker, true) ?? 'unknown'); + } + + if (!typeArguments?.length) { + typeArguments = + type.aliasTypeArguments?.map( + (x) => getTypeName(x, undefined, checker, true) ?? 'unknown', + ) ?? []; + } } if (typeArguments && typeArguments.length > 0) { diff --git a/test/aliases/input.ts b/test/aliases/input.ts new file mode 100644 index 0000000..565658d --- /dev/null +++ b/test/aliases/input.ts @@ -0,0 +1,12 @@ +export interface A { + a: Alias; + r: MyRecord; + s: AliasToGeneric; +} + +export function fn1(a: Alias, r: MyRecord, s: AliasToGeneric) {} + +type SomeType = 1 | 2; +type Alias = SomeType; +type MyRecord = Record; +type AliasToGeneric = Set; diff --git a/test/aliases/output.json b/test/aliases/output.json new file mode 100644 index 0000000..f47cd70 --- /dev/null +++ b/test/aliases/output.json @@ -0,0 +1,116 @@ +{ + "name": "test/aliases/input", + "exports": [ + { + "name": "fn1", + "type": { + "kind": "function", + "name": "fn1", + "parentNamespaces": [], + "callSignatures": [ + { + "parameters": [ + { + "type": { + "kind": "union", + "types": [ + { + "kind": "literal", + "parentNamespaces": [], + "value": 1 + }, + { + "kind": "literal", + "parentNamespaces": [], + "value": 2 + } + ], + "parentNamespaces": [], + "name": "Alias" + }, + "name": "a", + "optional": false + }, + { + "type": { + "kind": "object", + "name": "MyRecord", + "parentNamespaces": [], + "properties": [] + }, + "name": "r", + "optional": false + }, + { + "type": { + "kind": "object", + "name": "AliasToGeneric", + "parentNamespaces": [], + "properties": [] + }, + "name": "s", + "optional": false + } + ], + "returnValueType": { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "void" + } + } + ] + } + }, + { + "name": "A", + "type": { + "kind": "object", + "name": "A", + "parentNamespaces": [], + "properties": [ + { + "name": "a", + "type": { + "kind": "union", + "types": [ + { + "kind": "literal", + "parentNamespaces": [], + "value": 1 + }, + { + "kind": "literal", + "parentNamespaces": [], + "value": 2 + } + ], + "parentNamespaces": [], + "name": "Alias" + }, + "optional": false + }, + { + "name": "r", + "type": { + "kind": "object", + "name": "MyRecord", + "parentNamespaces": [], + "properties": [] + }, + "optional": false + }, + { + "name": "s", + "type": { + "kind": "object", + "name": "AliasToGeneric", + "parentNamespaces": [], + "properties": [] + }, + "optional": false + } + ] + } + } + ] +} \ No newline at end of file diff --git a/test/arrays/output.json b/test/arrays/output.json index 0f47648..9cac120 100644 --- a/test/arrays/output.json +++ b/test/arrays/output.json @@ -61,8 +61,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -85,8 +84,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } diff --git a/test/base-ui-component/input.tsx b/test/base-ui-component/input.tsx index d8dd0b8..c86bc7d 100644 --- a/test/base-ui-component/input.tsx +++ b/test/base-ui-component/input.tsx @@ -1,13 +1,13 @@ import * as React from 'react'; -export const BaseUIComponent = React.forwardRef(function BaseUIComponent( - props: BaseUIComponent.Props, +export const BaseUIComponent1 = React.forwardRef(function BaseUIComponent( + props: BaseUIComponent1.Props, ref: React.ForwardedRef, ) { return
; }); -export namespace BaseUIComponent { +export namespace BaseUIComponent1 { export interface Props extends BaseUIComponentProps<'div', State> { value?: string; onValueChange?: (value: string) => void; @@ -23,36 +23,47 @@ export namespace BaseUIComponent { } } +export const BaseUIComponent2 = React.forwardRef(function BaseUIComponent( + props: BaseUIComponent2.Props, + ref: React.ForwardedRef, +) { + return
; +}); + +export namespace BaseUIComponent2 { + export interface Props extends BaseUIComponentProps<'div', State> {} + + export interface State {} +} + type BaseUIComponentProps< ElementType extends React.ElementType, State, - RenderFunctionProps = GenericHTMLProps, -> = Omit>, 'className'> & { - /** - * CSS class applied to the element, or a function that - * returns a class based on the component’s state. - */ + RenderFunctionProps = HTMLProps, +> = Omit< + WithBaseUIEvent>, + 'className' | 'color' | 'defaultValue' | 'defaultChecked' +> & { className?: string | ((state: State) => string); - /** - * Allows you to replace the component’s HTML element - * with a different tag, or compose it with another component. - * - * Accepts a `ReactElement` or a function that returns the element to render. - */ render?: | ComponentRenderFn | React.ReactElement>; }; -type ComponentRenderFn = (props: Props, state: State) => React.ReactElement; +export type ComponentRenderFn = ( + props: Props, + state: State, +) => React.ReactElement; type WithBaseUIEvent = { [K in keyof T]: WithPreventBaseUIHandler; }; -export type GenericHTMLProps = React.HTMLAttributes & { ref?: React.Ref | undefined }; +type HTMLProps = React.HTMLAttributes & { + ref?: React.Ref | undefined; +}; -export type BaseUIEvent> = E & { +type BaseUIEvent> = E & { preventBaseUIHandler: () => void; readonly baseUIHandlerPrevented?: boolean; }; diff --git a/test/base-ui-component/output.json b/test/base-ui-component/output.json index 2d61309..2d5009a 100644 --- a/test/base-ui-component/output.json +++ b/test/base-ui-component/output.json @@ -2,7 +2,7 @@ "name": "test/base-ui-component/input", "exports": [ { - "name": "BaseUIComponent", + "name": "BaseUIComponent1", "type": { "kind": "component", "name": "ForwardRefExoticComponent", @@ -23,8 +23,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -62,8 +61,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -84,8 +82,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -110,7 +107,7 @@ "kind": "object", "name": "State", "parentNamespaces": [ - "BaseUIComponent" + "BaseUIComponent1" ], "properties": [ { @@ -141,12 +138,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] - }, - "documentation": { - "description": "CSS class applied to the element, or a function that\nreturns a class based on the component’s state.", - "tags": [] + ] }, "optional": true }, @@ -201,16 +193,15 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } ] } ], - "name": "GenericHTMLProps", "parentNamespaces": [], + "name": "HTMLProps", "properties": [ { "name": "ref", @@ -229,8 +220,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } @@ -244,7 +234,7 @@ "kind": "object", "name": "State", "parentNamespaces": [ - "BaseUIComponent" + "BaseUIComponent1" ], "properties": [ { @@ -277,12 +267,182 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, - "documentation": { - "description": "Allows you to replace the component’s HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render.", - "tags": [] + "optional": true + } + ] + } + }, + { + "name": "BaseUIComponent2", + "type": { + "kind": "component", + "name": "ForwardRefExoticComponent", + "parentNamespaces": [], + "props": [ + { + "name": "className", + "type": { + "kind": "union", + "types": [ + { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "string" + }, + { + "kind": "function", + "parentNamespaces": [], + "callSignatures": [ + { + "parameters": [ + { + "type": { + "kind": "object", + "name": "State", + "parentNamespaces": [ + "BaseUIComponent2" + ], + "properties": [] + }, + "name": "state", + "optional": false + } + ], + "returnValueType": { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "string" + } + } + ] + }, + { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "undefined" + } + ] + }, + "optional": true + }, + { + "name": "render", + "type": { + "kind": "union", + "types": [ + { + "kind": "reference", + "name": "ReactElement, string | JSXElementConstructor>", + "parentNamespaces": [ + "React" + ] + }, + { + "kind": "function", + "name": "ComponentRenderFn", + "parentNamespaces": [], + "callSignatures": [ + { + "parameters": [ + { + "type": { + "kind": "intersection", + "types": [ + { + "kind": "reference", + "name": "HTMLAttributes", + "parentNamespaces": [ + "React" + ] + }, + { + "kind": "object", + "parentNamespaces": [], + "properties": [ + { + "name": "ref", + "type": { + "kind": "union", + "types": [ + { + "kind": "reference", + "name": "Ref", + "parentNamespaces": [ + "React" + ] + }, + { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "undefined" + } + ] + }, + "optional": true + } + ] + } + ], + "parentNamespaces": [], + "name": "HTMLProps", + "properties": [ + { + "name": "ref", + "type": { + "kind": "union", + "types": [ + { + "kind": "reference", + "name": "Ref", + "parentNamespaces": [ + "React" + ] + }, + { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "undefined" + } + ] + }, + "optional": true + } + ] + }, + "name": "props", + "optional": false + }, + { + "type": { + "kind": "object", + "name": "State", + "parentNamespaces": [ + "BaseUIComponent2" + ], + "properties": [] + }, + "name": "state", + "optional": false + } + ], + "returnValueType": { + "kind": "reference", + "name": "ReactElement>", + "parentNamespaces": [ + "React" + ] + } + } + ] + }, + { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "undefined" + } + ] }, "optional": true } diff --git a/test/component-function-declaration/output.json b/test/component-function-declaration/output.json index d842d4f..1dda460 100644 --- a/test/component-function-declaration/output.json +++ b/test/component-function-declaration/output.json @@ -23,8 +23,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } diff --git a/test/component-function-variable/output.json b/test/component-function-variable/output.json index b9a32c2..185a1e7 100644 --- a/test/component-function-variable/output.json +++ b/test/component-function-variable/output.json @@ -23,8 +23,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -43,8 +42,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } @@ -73,8 +71,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -93,8 +90,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } @@ -123,8 +119,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -143,8 +138,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } diff --git a/test/conditional-types/output.json b/test/conditional-types/output.json index b04e5b5..d128810 100644 --- a/test/conditional-types/output.json +++ b/test/conditional-types/output.json @@ -34,8 +34,7 @@ "parentNamespaces": [], "name": "null" } - ], - "parentNamespaces": [] + ] } } ] @@ -53,7 +52,7 @@ { "type": { "kind": "object", - "name": "Props", + "name": "Props", "parentNamespaces": [], "properties": [ { @@ -80,8 +79,7 @@ "parentNamespaces": [], "name": "null" } - ], - "parentNamespaces": [] + ] }, "optional": false } diff --git a/test/forwardRef/output.json b/test/forwardRef/output.json index 5affaea..88f9290 100644 --- a/test/forwardRef/output.json +++ b/test/forwardRef/output.json @@ -23,8 +23,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -43,8 +42,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } diff --git a/test/function-optional-parameters/output.json b/test/function-optional-parameters/output.json index 7315951..689c485 100644 --- a/test/function-optional-parameters/output.json +++ b/test/function-optional-parameters/output.json @@ -33,8 +33,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "name": "optional", "documentation": { diff --git a/test/generics-closed-parameters/input.ts b/test/generics-closed-parameters/input.ts new file mode 100644 index 0000000..a3bf78b --- /dev/null +++ b/test/generics-closed-parameters/input.ts @@ -0,0 +1,9 @@ +export function test(a: GenericObject) { + return null; +} + +type GenericObject = { + x: T; +}; + +type MyUnion = string | number; diff --git a/test/generics-closed-parameters/output.json b/test/generics-closed-parameters/output.json new file mode 100644 index 0000000..8247328 --- /dev/null +++ b/test/generics-closed-parameters/output.json @@ -0,0 +1,56 @@ +{ + "name": "test/generics-closed-parameters/input", + "exports": [ + { + "name": "test", + "type": { + "kind": "function", + "name": "test", + "parentNamespaces": [], + "callSignatures": [ + { + "parameters": [ + { + "type": { + "kind": "object", + "name": "GenericObject", + "parentNamespaces": [], + "properties": [ + { + "name": "x", + "type": { + "kind": "union", + "types": [ + { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "string" + }, + { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "number" + } + ], + "parentNamespaces": [], + "name": "MyUnion" + }, + "optional": false + } + ] + }, + "name": "a", + "optional": false + } + ], + "returnValueType": { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "null" + } + } + ] + } + } + ] +} \ No newline at end of file diff --git a/test/generics-closed/input.ts b/test/generics-closed/input.ts new file mode 100644 index 0000000..e2b0e42 --- /dev/null +++ b/test/generics-closed/input.ts @@ -0,0 +1,18 @@ +type ComponentProps = { + className?: string | ((state: TState) => string); + render?: ComponentRenderFn; +}; + +export function fn(props: MyComponent.Props) {} + +type ComponentRenderFn = (props: Props, state: State) => React.ReactElement; + +export type GenericHTMLProps = React.HTMLAttributes & { ref?: React.Ref | undefined }; + +namespace MyComponent { + export interface State { + disabled: boolean; + } + + export interface Props extends ComponentProps {} +} diff --git a/test/generics-closed/output.json b/test/generics-closed/output.json new file mode 100644 index 0000000..8cde6d6 --- /dev/null +++ b/test/generics-closed/output.json @@ -0,0 +1,215 @@ +{ + "name": "test/generics-closed/input", + "exports": [ + { + "name": "fn", + "type": { + "kind": "function", + "name": "fn", + "parentNamespaces": [], + "callSignatures": [ + { + "parameters": [ + { + "type": { + "kind": "object", + "name": "Props", + "parentNamespaces": [ + "MyComponent" + ], + "properties": [ + { + "name": "className", + "type": { + "kind": "union", + "types": [ + { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "string" + }, + { + "kind": "function", + "parentNamespaces": [], + "callSignatures": [ + { + "parameters": [ + { + "type": { + "kind": "object", + "name": "State", + "parentNamespaces": [ + "MyComponent" + ], + "properties": [ + { + "name": "disabled", + "type": { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "boolean" + }, + "optional": false + } + ] + }, + "name": "state", + "optional": false + } + ], + "returnValueType": { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "string" + } + } + ] + }, + { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "undefined" + } + ] + }, + "optional": true + }, + { + "name": "render", + "type": { + "kind": "union", + "types": [ + { + "kind": "function", + "name": "ComponentRenderFn", + "parentNamespaces": [], + "callSignatures": [ + { + "parameters": [ + { + "type": { + "kind": "intersection", + "types": [ + { + "kind": "reference", + "name": "HTMLAttributes", + "parentNamespaces": [ + "React" + ] + }, + { + "kind": "object", + "parentNamespaces": [], + "properties": [ + { + "name": "ref", + "type": { + "kind": "union", + "types": [ + { + "kind": "reference", + "name": "Ref", + "parentNamespaces": [ + "React" + ] + }, + { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "undefined" + } + ] + }, + "optional": true + } + ] + } + ], + "parentNamespaces": [], + "name": "GenericHTMLProps", + "properties": [ + { + "name": "ref", + "type": { + "kind": "union", + "types": [ + { + "kind": "reference", + "name": "Ref", + "parentNamespaces": [ + "React" + ] + }, + { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "undefined" + } + ] + }, + "optional": true + } + ] + }, + "name": "props", + "optional": false + }, + { + "type": { + "kind": "object", + "name": "State", + "parentNamespaces": [ + "MyComponent" + ], + "properties": [ + { + "name": "disabled", + "type": { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "boolean" + }, + "optional": false + } + ] + }, + "name": "state", + "optional": false + } + ], + "returnValueType": { + "kind": "reference", + "name": "ReactElement>", + "parentNamespaces": [ + "React" + ] + } + } + ] + }, + { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "undefined" + } + ] + }, + "optional": true + } + ] + }, + "name": "props", + "optional": false + } + ], + "returnValueType": { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "void" + } + } + ] + } + } + ] +} \ No newline at end of file diff --git a/test/generics/output.json b/test/generics/output.json index 1c5f5ca..0c87994 100644 --- a/test/generics/output.json +++ b/test/generics/output.json @@ -13,7 +13,7 @@ { "type": { "kind": "object", - "name": "GenericFunctionParameters", + "name": "GenericFunctionParameters", "parentNamespaces": [], "properties": [ { @@ -30,14 +30,14 @@ "name": "nestedGenericType", "type": { "kind": "object", - "name": "GenericInterface", + "name": "GenericInterface>", "parentNamespaces": [], "properties": [ { "name": "data", "type": { "kind": "object", - "name": "GenericInterface", + "name": "GenericInterface", "parentNamespaces": [], "properties": [ { diff --git a/test/hook-arrow-function/output.json b/test/hook-arrow-function/output.json index 45f5385..de99ff0 100644 --- a/test/hook-arrow-function/output.json +++ b/test/hook-arrow-function/output.json @@ -109,7 +109,9 @@ "type": { "kind": "reference", "name": "RefCallback", - "parentNamespaces": [] + "parentNamespaces": [ + "React" + ] }, "optional": false } diff --git a/test/hook-function-expression/output.json b/test/hook-function-expression/output.json index d57dc9f..a324367 100644 --- a/test/hook-function-expression/output.json +++ b/test/hook-function-expression/output.json @@ -110,7 +110,9 @@ "type": { "kind": "reference", "name": "RefCallback", - "parentNamespaces": [] + "parentNamespaces": [ + "React" + ] }, "optional": false } diff --git a/test/hook-function/output.json b/test/hook-function/output.json index 90ddf70..aac3c46 100644 --- a/test/hook-function/output.json +++ b/test/hook-function/output.json @@ -110,7 +110,9 @@ "type": { "kind": "reference", "name": "RefCallback", - "parentNamespaces": [] + "parentNamespaces": [ + "React" + ] }, "optional": false } diff --git a/test/hook-multiple-parameters/output.json b/test/hook-multiple-parameters/output.json index fdb944e..14b20e6 100644 --- a/test/hook-multiple-parameters/output.json +++ b/test/hook-multiple-parameters/output.json @@ -70,8 +70,8 @@ "value": "\"high\"" } ], - "name": "Severity", - "parentNamespaces": [] + "parentNamespaces": [], + "name": "Severity" }, "name": "severity", "documentation": { diff --git a/test/interfaces/output.json b/test/interfaces/output.json index ea8bec6..69192e8 100644 --- a/test/interfaces/output.json +++ b/test/interfaces/output.json @@ -98,8 +98,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } diff --git a/test/intersection-types/output.json b/test/intersection-types/output.json index 43c54e0..7c72557 100644 --- a/test/intersection-types/output.json +++ b/test/intersection-types/output.json @@ -59,8 +59,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -79,15 +78,13 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } ] } ], - "parentNamespaces": [], "properties": [ { "name": "a", @@ -122,8 +119,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } @@ -200,8 +196,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -220,16 +215,15 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } ] } ], - "name": "AB", "parentNamespaces": [], + "name": "AB", "properties": [ { "name": "a", @@ -264,8 +258,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } diff --git a/test/jsdoc-extra-tags/output.json b/test/jsdoc-extra-tags/output.json index 9fd2250..7c0664c 100644 --- a/test/jsdoc-extra-tags/output.json +++ b/test/jsdoc-extra-tags/output.json @@ -75,8 +75,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "name": "reason", "documentation": { @@ -116,8 +115,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "documentation": { "description": "For internal use only", diff --git a/test/jsdocs/output.json b/test/jsdocs/output.json index 7a0ced8..0ce780f 100644 --- a/test/jsdocs/output.json +++ b/test/jsdocs/output.json @@ -23,8 +23,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "documentation": { "description": "The class name.\nUsed to make the component more classy.", @@ -47,8 +46,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "documentation": { "description": "A value.", @@ -101,8 +99,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "name": "p2", "documentation": { @@ -147,8 +144,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "name": "p2", "documentation": { diff --git a/test/literal-unions/output.json b/test/literal-unions/output.json index 56e4d73..a600da7 100644 --- a/test/literal-unions/output.json +++ b/test/literal-unions/output.json @@ -36,8 +36,7 @@ "parentNamespaces": [], "value": "\"baz\"" } - ], - "parentNamespaces": [] + ] }, "optional": false }, @@ -61,8 +60,7 @@ "parentNamespaces": [], "value": 3 } - ], - "parentNamespaces": [] + ] }, "optional": false }, @@ -87,8 +85,8 @@ "value": "\"baz\"" } ], - "name": "StringUnion", - "parentNamespaces": [] + "parentNamespaces": [], + "name": "StringUnion" }, "optional": false }, @@ -113,8 +111,8 @@ "value": 3 } ], - "name": "NumberUnion", - "parentNamespaces": [] + "parentNamespaces": [], + "name": "NumberUnion" }, "optional": false }, @@ -149,16 +147,15 @@ "value": "\"baz\"" } ], - "name": "StringUnion", - "parentNamespaces": [] + "parentNamespaces": [], + "name": "StringUnion" }, { "kind": "intrinsic", "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "name": "ref", "optional": false @@ -198,8 +195,8 @@ "value": "\"baz\"" } ], - "name": "StringUnion", - "parentNamespaces": [] + "parentNamespaces": [], + "name": "StringUnion" }, { "kind": "union", @@ -220,11 +217,10 @@ "value": 3 } ], - "name": "NumberUnion", - "parentNamespaces": [] + "parentNamespaces": [], + "name": "NumberUnion" } - ], - "parentNamespaces": [] + ] }, "optional": false }, @@ -255,8 +251,8 @@ "value": "\"baz\"" } ], - "name": "StringUnion", - "parentNamespaces": [] + "parentNamespaces": [], + "name": "StringUnion" }, { "kind": "literal", @@ -264,16 +260,15 @@ "value": "\"qux\"" } ], - "name": "IndirectStringUnion", - "parentNamespaces": [] + "parentNamespaces": [], + "name": "IndirectStringUnion" }, { "kind": "intrinsic", "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": false } @@ -320,8 +315,7 @@ "parentNamespaces": [], "value": "\"baz\"" } - ], - "parentNamespaces": [] + ] }, "name": "inlineStringUnion", "optional": false @@ -345,8 +339,7 @@ "parentNamespaces": [], "value": 3 } - ], - "parentNamespaces": [] + ] }, "name": "inlineNumberUnion", "optional": false @@ -371,8 +364,8 @@ "value": "\"baz\"" } ], - "name": "StringUnion", - "parentNamespaces": [] + "parentNamespaces": [], + "name": "StringUnion" }, "name": "referencedStringUnion", "optional": false @@ -397,8 +390,8 @@ "value": 3 } ], - "name": "NumberUnion", - "parentNamespaces": [] + "parentNamespaces": [], + "name": "NumberUnion" }, "name": "referencedNumberUnion", "optional": false @@ -426,8 +419,8 @@ "value": "\"baz\"" } ], - "name": "StringUnion", - "parentNamespaces": [] + "parentNamespaces": [], + "name": "StringUnion" }, { "kind": "union", @@ -448,11 +441,10 @@ "value": 3 } ], - "name": "NumberUnion", - "parentNamespaces": [] + "parentNamespaces": [], + "name": "NumberUnion" } - ], - "parentNamespaces": [] + ] }, "name": "unionOfUnions", "optional": false @@ -483,8 +475,8 @@ "value": "\"baz\"" } ], - "name": "StringUnion", - "parentNamespaces": [] + "parentNamespaces": [], + "name": "StringUnion" }, { "kind": "literal", @@ -492,16 +484,15 @@ "value": "\"qux\"" } ], - "name": "IndirectStringUnion", - "parentNamespaces": [] + "parentNamespaces": [], + "name": "IndirectStringUnion" }, { "kind": "intrinsic", "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "name": "indirectUnion", "optional": false @@ -564,8 +555,7 @@ "parentNamespaces": [], "value": "\"indirectUnion\"" } - ], - "parentNamespaces": [] + ] }, "name": "prop", "optional": false diff --git a/test/mapped-types/output.json b/test/mapped-types/output.json index 1d4e217..63515b2 100644 --- a/test/mapped-types/output.json +++ b/test/mapped-types/output.json @@ -13,7 +13,7 @@ { "type": { "kind": "object", - "name": "Partial", + "name": "Partial", "parentNamespaces": [], "properties": [ { @@ -31,8 +31,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -51,8 +50,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } @@ -83,7 +81,7 @@ { "type": { "kind": "object", - "name": "Required", + "name": "Required", "parentNamespaces": [], "properties": [ { @@ -131,7 +129,7 @@ { "type": { "kind": "object", - "name": "Partial", + "name": "Partial", "parentNamespaces": [], "properties": [ { @@ -149,8 +147,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -169,8 +166,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } @@ -201,7 +197,7 @@ { "type": { "kind": "object", - "name": "Required", + "name": "Required", "parentNamespaces": [], "properties": [ { diff --git a/test/memo/output.json b/test/memo/output.json index 07a2bc5..a836287 100644 --- a/test/memo/output.json +++ b/test/memo/output.json @@ -23,8 +23,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -43,8 +42,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } diff --git a/test/mui-overridable-component/output.json b/test/mui-overridable-component/output.json index c11ed51..c41dc2d 100644 --- a/test/mui-overridable-component/output.json +++ b/test/mui-overridable-component/output.json @@ -23,8 +23,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "documentation": { "description": "The component used for the root node.", @@ -57,8 +56,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -77,8 +75,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -99,8 +96,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } diff --git a/test/namespaces/input.tsx b/test/namespaces/input.tsx index d57bb89..73bd157 100644 --- a/test/namespaces/input.tsx +++ b/test/namespaces/input.tsx @@ -4,6 +4,7 @@ export namespace Root { export interface Params { s: Grade; + a: NamespacedType; } export enum Grade { @@ -21,6 +22,12 @@ export namespace Root { } export function fn2() {} + + export type NamespacedType = OutsideType; } export function fn3(params: Root.Sub.Params) {} + +export function fn4(a: Root.NamespacedType) {} + +type OutsideType = 'one' | 'two'; diff --git a/test/namespaces/output.json b/test/namespaces/output.json index 2323452..4fbc136 100644 --- a/test/namespaces/output.json +++ b/test/namespaces/output.json @@ -40,6 +40,29 @@ ] }, "optional": false + }, + { + "name": "a", + "type": { + "kind": "union", + "types": [ + { + "kind": "literal", + "parentNamespaces": [], + "value": "\"one\"" + }, + { + "kind": "literal", + "parentNamespaces": [], + "value": "\"two\"" + } + ], + "parentNamespaces": [ + "Root" + ], + "name": "NamespacedType" + }, + "optional": false } ] }, @@ -56,6 +79,48 @@ ] } }, + { + "name": "fn4", + "type": { + "kind": "function", + "name": "fn4", + "parentNamespaces": [], + "callSignatures": [ + { + "parameters": [ + { + "type": { + "kind": "union", + "types": [ + { + "kind": "literal", + "parentNamespaces": [], + "value": "\"one\"" + }, + { + "kind": "literal", + "parentNamespaces": [], + "value": "\"two\"" + } + ], + "parentNamespaces": [ + "Root" + ], + "name": "NamespacedType" + }, + "name": "a", + "optional": false + } + ], + "returnValueType": { + "kind": "intrinsic", + "parentNamespaces": [], + "name": "void" + } + } + ] + } + }, { "name": "fn2", "type": { @@ -118,6 +183,29 @@ ] }, "optional": false + }, + { + "name": "a", + "type": { + "kind": "union", + "types": [ + { + "kind": "literal", + "parentNamespaces": [], + "value": "\"one\"" + }, + { + "kind": "literal", + "parentNamespaces": [], + "value": "\"two\"" + } + ], + "parentNamespaces": [ + "Root" + ], + "name": "NamespacedType" + }, + "optional": false } ] }, @@ -202,6 +290,29 @@ ] }, "optional": false + }, + { + "name": "a", + "type": { + "kind": "union", + "types": [ + { + "kind": "literal", + "parentNamespaces": [], + "value": "\"one\"" + }, + { + "kind": "literal", + "parentNamespaces": [], + "value": "\"two\"" + } + ], + "parentNamespaces": [ + "Root" + ], + "name": "NamespacedType" + }, + "optional": false } ] } diff --git a/test/props-optional/output.json b/test/props-optional/output.json index 273cad1..8eff7b2 100644 --- a/test/props-optional/output.json +++ b/test/props-optional/output.json @@ -32,8 +32,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -52,8 +51,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": false }, @@ -81,8 +79,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } diff --git a/test/props-with-callbacks/output.json b/test/props-with-callbacks/output.json index da8c2ac..08c322b 100644 --- a/test/props-with-callbacks/output.json +++ b/test/props-with-callbacks/output.json @@ -41,8 +41,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "name": "reason", "optional": false @@ -140,8 +139,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } diff --git a/test/react-event-handlers/output.json b/test/react-event-handlers/output.json index 064ece5..1915c0d 100644 --- a/test/react-event-handlers/output.json +++ b/test/react-event-handlers/output.json @@ -36,8 +36,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -69,8 +68,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } diff --git a/test/react-refs/output.json b/test/react-refs/output.json index d62def8..02743ed 100644 --- a/test/react-refs/output.json +++ b/test/react-refs/output.json @@ -24,7 +24,9 @@ "type": { "kind": "reference", "name": "RefCallback", - "parentNamespaces": [] + "parentNamespaces": [ + "React" + ] }, "optional": false }, @@ -56,8 +58,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -76,8 +77,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -98,8 +98,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } diff --git a/test/reference-types/output.json b/test/reference-types/output.json index 9071499..28ae860 100644 --- a/test/reference-types/output.json +++ b/test/reference-types/output.json @@ -86,8 +86,7 @@ } ] } - ], - "parentNamespaces": [] + ] } } ] diff --git a/test/ts-utility-types/output.json b/test/ts-utility-types/output.json index 9b7725d..bcd55d2 100644 --- a/test/ts-utility-types/output.json +++ b/test/ts-utility-types/output.json @@ -13,7 +13,7 @@ { "type": { "kind": "object", - "name": "Pick", + "name": "Pick", "parentNamespaces": [], "properties": [ { @@ -40,8 +40,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } @@ -72,7 +71,7 @@ { "type": { "kind": "object", - "name": "Omit", + "name": "Omit", "parentNamespaces": [], "properties": [ { @@ -99,8 +98,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } @@ -131,11 +129,12 @@ { "type": { "kind": "tuple", + "name": "Parameters", "parentNamespaces": [], "types": [ { "kind": "object", - "name": "Pick", + "name": "Pick", "parentNamespaces": [], "properties": [ { @@ -162,8 +161,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true } diff --git a/test/tuples/output.json b/test/tuples/output.json index 41c8aa9..2877842 100644 --- a/test/tuples/output.json +++ b/test/tuples/output.json @@ -70,6 +70,7 @@ "parameters": [], "returnValueType": { "kind": "tuple", + "name": "TupleType", "parentNamespaces": [], "types": [ { @@ -99,6 +100,7 @@ "parameters": [], "returnValueType": { "kind": "tuple", + "name": "NamedTupleType", "parentNamespaces": [], "types": [ { diff --git a/test/union-types/output.json b/test/union-types/output.json index 40e0431..e343f19 100644 --- a/test/union-types/output.json +++ b/test/union-types/output.json @@ -32,8 +32,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -52,8 +51,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }, @@ -72,8 +70,7 @@ "parentNamespaces": [], "name": "number" } - ], - "parentNamespaces": [] + ] }, "optional": false }, @@ -92,8 +89,7 @@ "parentNamespaces": [], "name": "undefined" } - ], - "parentNamespaces": [] + ] }, "optional": true }