diff --git a/src/vs/workbench/services/preferences/common/preferencesValidation.ts b/src/vs/workbench/services/preferences/common/preferencesValidation.ts index 5c911813f79..9eb757d502c 100644 --- a/src/vs/workbench/services/preferences/common/preferencesValidation.ts +++ b/src/vs/workbench/services/preferences/common/preferencesValidation.ts @@ -47,6 +47,10 @@ export function createValidator(prop: IConfigurationPropertySchema): (value: any } } + if (prop.type === 'boolean' && value !== true && value !== false) { + errors.push(nls.localize('validations.booleanIncorrectType', 'Incorrect type. Expected "boolean".')); + } + if (isNumeric) { if (isNullOrEmpty(value) || isNaN(+value)) { errors.push(nls.localize('validations.expectedNumeric', "Value must be a number.")); @@ -57,7 +61,7 @@ export function createValidator(prop: IConfigurationPropertySchema): (value: any if (prop.type === 'string') { if (!isString(value)) { - errors.push(nls.localize('validations.incorrectType', 'Incorrect type. Expected "string".')); + errors.push(nls.localize('validations.stringIncorrectType', 'Incorrect type. Expected "string".')); } else { errors.push(...stringValidations.filter(validator => !validator.isValid(value)).map(validator => validator.message)); } diff --git a/src/vs/workbench/services/preferences/test/common/preferencesValidation.test.ts b/src/vs/workbench/services/preferences/test/common/preferencesValidation.test.ts index bbb8419aa75..0ee46bad8e7 100644 --- a/src/vs/workbench/services/preferences/test/common/preferencesValidation.test.ts +++ b/src/vs/workbench/services/preferences/test/common/preferencesValidation.test.ts @@ -267,6 +267,16 @@ suite('Preferences Validation', () => { pattern.rejects({ '#ab': 99999 }); pattern.accepts({}); } + { + const pattern = new Tester({ type: 'object', properties: { 'hello': { type: 'string' } }, additionalProperties: { type: 'boolean' } }); + pattern.accepts({ 'hello': 'world' }); + pattern.accepts({ 'hello': 'world', 'bye': false }); + pattern.rejects({ 'hello': 'world', 'bye': 'false' }); + pattern.rejects({ 'hello': 'world', 'bye': 1 }); + pattern.rejects({ 'hello': 'world', 'bye': 'world' }); + pattern.accepts({ 'hello': 'test' }); + pattern.accepts({}); + } }); test('patterns work', () => {