How to access a field's default value on type

How can I access the default value of a field on the type in a non-member method.

here is example I have thought of, but does not work:

type MyParentType {
myDefaultFieldValue: string
getMyDefaultFieldValue: function() js server
}

and js implementation

getMyDefaultFieldValue function() {
return c3Type(c3CurrentAction().getTarget().getType()).make().myDefaultFieldValue;
}

then my subtype:



type MySubType extends MyParentType {
myDefaultFieldValue: ~ = 'A default value'
}

If I call MySubType.getMyDeFaultfieldValue() I want to get 'A default value'

Are you sure c3Type(c3CurrentAction().getTarget().getType()) gives you current type?
cause the rest seems correct as you are using = for your default values

1 Like

MySubType.make().getMyDefaultFieldValue() should give you what youre looking for.

@tony.li The method is implemented on MyParentType, so I don’t know what MySubType is in the method

@bachr that is the same code I currently have but I get error TypeError: Cannot find function make in object [object Object].

No I am not 100% sure

why do you need a function?

How about

c3Type(c3CurrentAction().getTarget().getType()).fieldType(‘myDefaultFieldValue’).initializerValue()

this.fieldType(‘myDefaultFieldValue’).initializerValue()

1 Like