import TypeAliasDeclaration from './TypeAliasDeclaration' ; import { Annotation , Type } from '@manta-style/core' ; export default class LazyTypeAliasDeclaration extends TypeAliasDeclaration { private initializer : ( currentType : TypeAliasDeclaration ) => Type = ( ) => this . type ; private initialized : boolean ; constructor ( name , annotations ) { super ( name , annotations ) ; this . initialized = false ; } public setInitialize ( initializer ) { this . initializer = initializer ; } public initialize ( ) { if ( ! this . initialized ) { this . setType ( this . initializer ( this ) ) ; this . initialized = true ; } } public getType ( ) { this . initialize ( ) ; return super . getType ( ) ; } public getAnnotations ( ) { this . initialize ( ) ; return super . getAnnotations ( ) ; } public deriveLiteral ( parentAnnotations ) { this . initialize ( ) ; return super . deriveLiteral ( parentAnnotations ) ; } public validate ( value ) { this . initialize ( ) ; return super . validate ( value ) ; } public format ( value ) { this . initialize ( ) ; return super . format ( value ) ; } public argumentTypes ( types ) { const typeAliasImplementation = new TypeAliasDeclaration ( this . name , this . annotations ) ; typeAliasImplementation . setType ( this . initializer ( typeAliasImplementation ) ) ; typeAliasImplementation . argumentTypes ( types ) ; return typeAliasImplementation ; } }