Class: CustomType
compiler.CustomType
Represents a custom type which is not a built-in type.
This type implements its own type constraints and can be used to represent complex type structures.
Since
0.12.0
Hierarchy
-
↳
CustomType
Table of contents
Constructors
Properties
Accessors
Methods
- assertAssignableTo
- getCompilableType
- getProperty
- isAssignableTo
- toString
- fromClassDeclaration
- fromInterfaceDeclaration
- fromObjectLiteral
Constructors
constructor
• Protected
new CustomType(identifier
, kind
, fields
, staticFields?
)
Parameters
Name | Type |
---|---|
identifier |
string |
kind |
CustomTypeKind |
fields |
CustomTypeFields |
staticFields? |
CustomTypeFields |
Overrides
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:64
Properties
_clsStaticFields
• Private
Optional
Readonly
_clsStaticFields: CustomTypeFields
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:38
_fields
• Private
Readonly
_fields: CustomTypeFields
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:37
_identifier
• Protected
Readonly
_identifier: string
Inherited from
Defined in
kipper/core/src/compiler/semantics/types/base/type.ts:9
clsExtends
• Optional
Readonly
clsExtends: CustomType
The type that this type extends. This is only applicable to classes.
Since
0.12.0
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:50
clsImplements
• Optional
Readonly
clsImplements: CustomType
[]
The types that this type implements. This is only applicable to classes.
Since
0.12.0
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:56
intfExtends
• Optional
Readonly
intfExtends: CustomType
The interface that this type extends. This is only applicable to interfaces.
Since
0.12.0
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:62
kind
• Readonly
kind: CustomTypeKind
The kind of this type. This is simply used to differentiate between classes and interfaces.
Since
0.12.0
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:44
Accessors
clsStaticFields
• get
clsStaticFields(): undefined
| CustomTypeFields
The static fields of this type. This is only applicable to classes.
Since
0.12.0
Returns
undefined
| CustomTypeFields
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:99
fields
• get
fields(): CustomTypeFields
The fields of this type.
Since
0.12.0
Returns
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:91
identifier
• get
identifier(): string
The identifier of this type.
Returns
string
Inherited from
ProcessedType.identifier
Defined in
kipper/core/src/compiler/semantics/types/base/processed-type.ts:19
isCompilable
• get
isCompilable(): boolean
Returns whether the type is compilable.
This runs through all fields and checks if they are compilable. As such this is an expensive operation and should only be used once during type checking.
Since
0.12.0
Returns
boolean
Overrides
ProcessedType.isCompilable
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:83
isGeneric
• get
isGeneric(): boolean
Returns whether the type is a generic type.
This is false unless overridden by a subclass.
Since
0.12.0
Returns
boolean
Inherited from
ProcessedType.isGeneric
Defined in
kipper/core/src/compiler/semantics/types/base/processed-type.ts:38
isUnion
• get
isUnion(): boolean
Returns whether the type is a union type.
Since
0.12.0
Returns
boolean
Inherited from
ProcessedType.isUnion
Defined in
kipper/core/src/compiler/semantics/types/base/processed-type.ts:46
Methods
assertAssignableTo
▸ assertAssignableTo(type
, propertyName?
, argumentName?
): void
Checks whether this type is assignable to another type.
This assumes that this is being assigned to type.
Throws
AssignmentTypeError If the types are not assignable.
Throws
PropertyAssignmentTypeError If a property is not assignable.
Throws
ArgumentAssignmentTypeError If an argument is not assignable.
Throws
PropertyNotFoundTypeError If a property is not found in this type.
Since
0.12.0
Parameters
Name | Type | Description |
---|---|---|
type |
ProcessedType |
The type to check against. |
propertyName? |
string |
The name of the property that is being assigned to. This is used for error messages. |
argumentName? |
string |
The name of the argument that is being assigned to. This is used for error messages. |
Returns
void
Overrides
ProcessedType.assertAssignableTo
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:168
getCompilableType
▸ getCompilableType(): CompilableType
Gets the compilable type for this type.
This function throws an error instead of returning undefined, since it's intended to be used in circumstances, where only due to a bug the type is not compilable. As such, it makes sense to strictly assert it will be compilable, unless an error occurs.
Throws
UndefinedType If the isCompilable is false, which should only occur if the identifier is of type UndefinedType.
Since
0.10.0
Returns
Inherited from
ProcessedType.getCompilableType
Defined in
kipper/core/src/compiler/semantics/types/base/processed-type.ts:60
getProperty
▸ getProperty(identifier
): undefined
| ProcessedType
Returns the field type for the passed identifier. May return undefined if the field does not exist.
Since
0.12.0
Parameters
Name | Type | Description |
---|---|---|
identifier |
string |
The identifier of the field to get. |
Returns
undefined
| ProcessedType
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:221
isAssignableTo
▸ isAssignableTo(type
): boolean
Returns whether this type is assignable to the given type. This discards any error messages.
This simply returns whether the assertAssignableTo function throws an error or not.
Since
0.12.0
Parameters
Name | Type | Description |
---|---|---|
type |
ProcessedType |
The type to check against. |
Returns
boolean
Inherited from
Defined in
kipper/core/src/compiler/semantics/types/base/processed-type.ts:84
toString
▸ toString(): string
Returns the full string representation of this type.
This also includes generic type arguments if this type is a generic type.
Since
0.12.0
Returns
string
Inherited from
Defined in
kipper/core/src/compiler/semantics/types/base/processed-type.ts:93
fromClassDeclaration
▸ Static
fromClassDeclaration(classDeclaration
): CustomType
Creates a custom type from a class declaration.
This can only be run AFTER the class declaration has passed semantic validation.
Since
0.12.0
Parameters
Name | Type | Description |
---|---|---|
classDeclaration |
ClassDeclaration |
The class declaration to create the custom type from. |
Returns
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:110
fromInterfaceDeclaration
▸ Static
fromInterfaceDeclaration(interfaceDeclaration
): CustomType
Creates a custom type from an interface declaration.
This can only be run AFTER the interface declaration has passed semantic validation.
Since
0.12.0
Parameters
Name | Type | Description |
---|---|---|
interfaceDeclaration |
InterfaceDeclaration |
The interface declaration to create the custom type from. |
Returns
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:129
fromObjectLiteral
▸ Static
fromObjectLiteral(objectPrimaryExpression
): CustomType
Creates a custom type from an object literal.
This can only be run AFTER the object primary expression has passed semantic validation.
Since
0.12.0
Parameters
Name | Type | Description |
---|---|---|
objectPrimaryExpression |
ObjectPrimaryExpression |
The object primary expression to create the custom type from. |
Returns
Defined in
kipper/core/src/compiler/semantics/types/custom-type.ts:146