codemix / babel-plugin-typecheck

Static and runtime type checking for JavaScript in the form of a Babel plugin.
MIT License
886 stars 44 forks source link

Add ability to define a strict object shape #145

Closed gajus closed 7 years ago

gajus commented 8 years ago

A strict object shape would restrict object to only the properties present in the object shape, i.e.

type TypeTest = {
    foo: string
};

const test = (test: TypeTest) => {

};

// This would work
test({
    foo: 'OK'
});

// This would throw an error
test({
    bar: 'NOT OK'
});

Denoting strict shape would require some sort of special syntax, e.g.

type TypeTest = strict<{
    foo: string
}>;

This syntax could be used for more add-ons, e.g.

type TypeTest = somethingElse<strict<{
    foo: string
}>>;
phpnode commented 7 years ago

flow-runtime has {| foo: string |} and $Shape<T>