import { isSerializable , deepFreeze , createScalarNode , IValidationContext , IValidationResult , typeCheckSuccess , typeCheckFailure , TypeFlags , isType , optional , IType , IAnyType , AnyObjectNode , SimpleType } from "../../internal" ; internal hidden export class Frozen < T > extends SimpleType < T , T , T > { flags = TypeFlags . Frozen ; constructor ( private subType ? ) { super ( subType ? `frozen(${ subType . name })` : "frozen" ) ; } describe ( ) { return "<any immutable value>" ; } instantiate ( parent , subpath , environment , value ) { return createScalarNode ( this , parent , subpath , environment , deepFreeze ( value ) ) ; } isValidSnapshot ( value , context ) { if ( ! isSerializable ( value ) ) { return typeCheckFailure ( context , value , "Value is not serializable and cannot be frozen" ) ; } if ( this . subType ) return this . subType . validate ( value , context ) ; return typeCheckSuccess ( ) ; } } const untypedFrozenInstance = new Frozen ( ) ; export function frozen < C > ( subType ) ; export function frozen < T > ( defaultValue ) ; export function frozen < T = any > ( ) ; param defaultValueOrType returns export function frozen ( arg ? ) { if ( arguments . length === 0 ) return untypedFrozenInstance ; else if ( isType ( arg ) ) return new Frozen ( arg ) ; else return optional ( untypedFrozenInstance , arg ) ; } param type returns export function isFrozenType < IT extends IType < T | any , T , T > , T = any > ( type ) { return isType ( type ) && ( type . flags & TypeFlags . Frozen ) > 0 ; }