typescript-docgen-types.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import ts, { HeritageClause } from 'typescript';
  2. export interface MethodParameterInfo {
  3. name: string;
  4. type: string;
  5. optional: boolean;
  6. initializer?: string;
  7. }
  8. export interface MemberInfo {
  9. name: string;
  10. description: string;
  11. type: string;
  12. fullText: string;
  13. modifiers: string[];
  14. since: string | undefined;
  15. }
  16. export interface PropertyInfo extends MemberInfo {
  17. kind: 'property';
  18. defaultValue: string;
  19. }
  20. export interface MethodInfo extends MemberInfo {
  21. kind: 'method';
  22. parameters: MethodParameterInfo[];
  23. }
  24. export interface DocsPage {
  25. title: string;
  26. category: string;
  27. declarations: ParsedDeclaration[];
  28. fileName: string;
  29. }
  30. export interface DeclarationInfo {
  31. packageName: string;
  32. sourceFile: string;
  33. sourceLine: number;
  34. title: string;
  35. fullText: string;
  36. weight: number;
  37. category: string;
  38. description: string;
  39. page: string | undefined;
  40. since: string | undefined;
  41. }
  42. export interface InterfaceInfo extends DeclarationInfo {
  43. kind: 'interface';
  44. extendsClause: HeritageClause | undefined;
  45. members: Array<PropertyInfo | MethodInfo>;
  46. }
  47. export interface ClassInfo extends DeclarationInfo {
  48. kind: 'class';
  49. extendsClause: HeritageClause | undefined;
  50. implementsClause: HeritageClause | undefined;
  51. members: Array<PropertyInfo | MethodInfo>;
  52. }
  53. export interface TypeAliasInfo extends DeclarationInfo {
  54. kind: 'typeAlias';
  55. members?: Array<PropertyInfo | MethodInfo>;
  56. type: ts.TypeNode;
  57. }
  58. export interface EnumInfo extends DeclarationInfo {
  59. kind: 'enum';
  60. members: PropertyInfo[];
  61. }
  62. export interface FunctionInfo extends DeclarationInfo {
  63. kind: 'function';
  64. parameters: MethodParameterInfo[];
  65. type?: ts.TypeNode;
  66. }
  67. export interface VariableInfo extends DeclarationInfo {
  68. kind: 'variable';
  69. }
  70. export type ParsedDeclaration =
  71. | TypeAliasInfo
  72. | ClassInfo
  73. | InterfaceInfo
  74. | EnumInfo
  75. | FunctionInfo
  76. | VariableInfo;
  77. export type ValidDeclaration =
  78. | ts.InterfaceDeclaration
  79. | ts.TypeAliasDeclaration
  80. | ts.ClassDeclaration
  81. | ts.EnumDeclaration
  82. | ts.FunctionDeclaration
  83. | ts.VariableStatement;
  84. export type TypeMap = Map<string, string>;