Add full interface support which allows the user to define interfaces and match objects against them.
For example:
interface X {
x: num;
y: num;
}
var x: X = {
x: 1,
y: 2,
};
This issue does NOT implement casts or conversions of objects but focuses solely on the support of defining an object with an interface type and letting the user provide constraints on variables or arguments that must have the specific object type.
Exact behaviour / changes you want
[x] Add semantic analysis and type checking for the interface AST node.
[x] Add internal translation of the interface definition to an internal type representation, which can then be used to match against objects.
[x] Implement support for "custom types" in the form of interfaces (such as var x: X where X is the custom type), which can be used as a value in variable and function declarations and can be checked against.
Is there an existing proposal for this?
This feature does not exist in the latest version
Proposal
Add full interface support which allows the user to define interfaces and match objects against them.
For example:
This issue does NOT implement casts or conversions of objects but focuses solely on the support of defining an object with an interface type and letting the user provide constraints on variables or arguments that must have the specific object type.
Exact behaviour / changes you want
var x: X
whereX
is the custom type), which can be used as a value in variable and function declarations and can be checked against.