| 5 | import { Writer } from './Writer'; |
| 6 | |
| 7 | export class TypeDeclaration<InnerType extends TypeBuilder = TypeBuilder> implements BasicBuilder { |
| 8 | private genericParameters: GenericParameter[] = []; |
| 9 | private docComment?: DocComment; |
| 10 | |
| 11 | constructor( |
| 12 | public name: string, |
| 13 | private type: InnerType | string |
| 14 | ) {} |
| 15 | |
| 16 | addGenericParameter(param: GenericParameter): this { |
| 17 | this.genericParameters.push(param); |
| 18 | return this; |
| 19 | } |
| 20 | |
| 21 | setName(name: string) { |
| 22 | this.name = name; |
| 23 | return this; |
| 24 | } |
| 25 | |
| 26 | setValue(typeDecl: string) { |
| 27 | this.type = typeDecl; |
| 28 | } |
| 29 | |
| 30 | setDocComment(docComment: DocComment): this { |
| 31 | this.docComment = docComment; |
| 32 | return this; |
| 33 | } |
| 34 | |
| 35 | write(writer: Writer): void { |
| 36 | if (this.docComment) { |
| 37 | writer.write(this.docComment); |
| 38 | } |
| 39 | |
| 40 | if (typeof this.type === 'string') { |
| 41 | writer.write(this.type); |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | writer.write('type ').write(this.name); |
| 46 | if (this.genericParameters.length > 0) { |
| 47 | writer.write('<').writeJoined(', ', this.genericParameters).write('>'); |
| 48 | } |
| 49 | writer.write(' = ').write(this.type); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | export function typeDeclaration<InnerType extends TypeBuilder = TypeBuilder>( |
| 54 | name: string, |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…