必要に応じて、動的インターフェイスチェッカーを試してください。例を次に示します(完全な例)。
interface PhysicalObject { color : Color; intact : bool; weight : number; }
class Car implements PhysicalObject {
public intact = true;
constructor(public color : Color, public weight : number) {};
}
function scratch(aCar : Car) {
typeCheck(JSVenv, arguments, schemas, ["PhysicalObject"]);
console.log("Scratching the car!");
aCar.intact = false;
}
と同等のコードscratch({ intact: 42, color: Color.RED })
が呼び出されると、次のようなエラーがスローされます。
AssertionError: Runtime typecheck failed on argument number 1:
Value: { color: 0, weight: 'four', intact: true },
Schema: ...,
Error reports (length 1):
[
{
uri: 'urn:uuid:b9b8e6fd-b14b-490d-9372-d2bd22e8a246#/weight',
schemaUri: 'urn:uuid:c76ddd92-15da-43a6-831e-6717f253efe5#/properties/weight',
attribute: 'type',
message: 'Instance is not a required type',
details: [ 'number' ]
}
]
手順については、メインページを参照してください:https ://github.com/ysangkok/typescript-interface-to-jsonschema
自動タイプチェックを追加しますが、TypeScriptにはnode-falafelのようなものが必要です。