Merge pull request #3150 from spotify/rugvip/docs

docgen: add support for picking up the type from the declaration instead of initialization
This commit is contained in:
Patrik Oldsberg
2020-11-02 16:57:32 +01:00
committed by GitHub
19 changed files with 243 additions and 105 deletions
@@ -99,7 +99,7 @@ export type PendingAuthRequest = {
export type OAuthRequestApi = {
/**
* A utility for showing login popups or similar things, and merging together multiple requests for
* different scopes into one request that inclues all scopes.
* different scopes into one request that includes all scopes.
*
* The passed in options provide information about the login provider, and how to handle auth requests.
*
@@ -114,7 +114,7 @@ export type OAuthRequestApi = {
): AuthRequester<AuthResponse>;
/**
* Observers panding auth requests. The returned observable will emit all
* Observers pending auth requests. The returned observable will emit all
* current active auth request, at most one for each created auth requester.
*
* Each request has its own info about the login provider, forwarded from the auth requester options.
@@ -52,7 +52,7 @@ export interface StorageApi {
remove(key: string): Promise<void>;
/**
* Save persistant data, and emit messages to anyone that is using observe$ for this key
* Save persistent data, and emit messages to anyone that is using observe$ for this key
*
* @param {String} key Unique key associated with the data.
*/
+1 -1
View File
@@ -15,7 +15,7 @@
*/
/**
* This file contains non-react related core types used throught Backstage.
* This file contains non-react related core types used throughout Backstage.
*/
/**
+12 -9
View File
@@ -76,13 +76,7 @@ export default class TypeLocator {
return;
}
docMap.get(decl.constructorType)!.push({
node,
name: decl.name,
source,
args: Array.from(decl.initializer.arguments || []),
typeArgs: Array.from(decl.initializer.typeArguments || []),
});
docMap.get(decl.constructorType)!.push({ node, source, ...decl });
});
});
@@ -103,7 +97,8 @@ export default class TypeLocator {
):
| {
constructorType: ts.Type;
initializer: ts.CallExpression | ts.NewExpression;
args: ts.Expression[];
typeArgs: ts.TypeNode[];
name: string;
}
| undefined {
@@ -137,6 +132,14 @@ export default class TypeLocator {
const constructorType = this.checker.getTypeAtLocation(
initializer.expression,
);
return { constructorType, initializer, name: name.text };
const args = Array.from(initializer.arguments ?? []);
const typeNode = declaration.type;
const typeArgs = Array.from(
(typeNode && ts.isTypeReferenceNode(typeNode)
? typeNode.typeArguments
: initializer.typeArguments) ?? [],
);
return { constructorType, args, typeArgs, name: name.text };
}
}