It's a sandbox project to testing VS Code and JavaScript + JSDoc type checking.
Read more: https://medium.com/@trukrs/type-safe-javascript-with-jsdoc-7a2a63209b76
YOU MUST ENABLE VALIDATION IN VS CODE PREFERENCES
javascript.validate.enable=true
( Related issue: microsoft/vscode#39305 )
Optionally, you can turn on checking feature to all files:
"javascript.implicitProjectConfig.checkJs": true
JSDoc support in VS Code:
- https://github.com/Microsoft/TypeScript/wiki/JsDoc-support-in-JavaScript
- https://github.com/Microsoft/TypeScript/wiki/JavaScript-Language-Service-in-Visual-Studio#JsDoc
When you edit your code, the VS Code checking JavaScript files automatically based on JSDoc.
Age must be a number.
// Wrong type!
const jane = new Person({
name: 'Jane Doe',
age: '10',
})
VS Code shows a message about this error:
- line:
(property) age?: number
- means it is optional and number - line:
optional, must be between 0-150, default is 0
- textual documentation - line:
Type 'string' is not assignable to type 'number'.ts(2322)
- error message - line:
person.js(6, 8): The expected type comes from property 'age' which is declared here on type '{ name: string; age?: number; }'
– detailed error description: you can click on person.js for more information