declareOpts: @flow

Reviewed By: cpojer

Differential Revision: D4146711

fbshipit-source-id: edd360b3dd8444c7ec5be5c69db97e1e0906a730
This commit is contained in:
Jean Lauliac 2016-11-08 04:46:13 -08:00 committed by Facebook Github Bot
parent f1aba3f63b
commit d25047ebf1
1 changed files with 12 additions and 1 deletions

View File

@ -15,13 +15,24 @@
* }); * });
* *
* var myOptions = validate(someOptions); * var myOptions = validate(someOptions);
*
* @flow
*/ */
'use strict'; 'use strict';
var Joi = require('joi'); var Joi = require('joi');
module.exports = function(descriptor) { /**
* TOut is always more specific than TIn, so it's a subtype.
*/
module.exports = function<TIn: {}, TOut: TIn>(
descriptor: {[name: string]: {
type: mixed,
required?: boolean,
default?: mixed,
}},
): (untyped: TIn) => TOut {
var joiKeys = {}; var joiKeys = {};
Object.keys(descriptor).forEach(function(prop) { Object.keys(descriptor).forEach(function(prop) {
var record = descriptor[prop]; var record = descriptor[prop];