DefinitelyTyped/types/js-schema/js-schema-tests.ts
robin labat ca336951d0 Correction of @types/js-schema for the import error: (#16090)
'Cannot invoke an expression whose type lacks a call signature. Type 'typeof 'js-schema'' has no compatible call signatures.'

while importing with 'import * as schema from 'js-schema''

The previous import strategie ('import {default as schema} from 'js-schema') where raising an error after compilation.
2017-05-04 17:55:53 -07:00

18 lines
655 B
TypeScript

import * as schema from 'js-schema';
var Duck = schema({ // A duck
swim : Function, // - can swim
quack : Function, // - can quack
age : Number.min(0).max(5), // - is 0 to 5 years old
color : ['yellow', 'brown'] // - has either yellow or brown color
});
// Some animals
var myDuck = { swim : function() {}, quack : function() {}, age : 2, color : 'yellow' },
myCat = { walk : function() {}, purr : function() {}, age : 3, color : 'black' },
animals = [ myDuck, myCat, {}, /*...*/ ];
// Simple checks
console.log( Duck(myDuck) ); // true
console.log( Duck(myCat) ); // false