码迷,mamicode.com
首页 > 编程语言 > 详细

[TypeScript] Type check JavaScript files using JSDoc and Typescript 2.5

时间:2017-09-09 21:37:29      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:use   with   sse   add   ict   java   install   vscode   esc   

Typescript 2.5 adds JSDoc type assertion support for javascript file via ts-check service.

 

First of all, you should make sure you have typescript@2.5 install:

sudo npm i -g typescript@2.5

 

Then add @ts-check to the top of js file:

// @ts-check

This tell typescript to check the file.

 

Check type assertion we can do:

// index.js

function
shouldBeNumber (/** @type {Number} */ num) { ‘use strict‘; console.log(num) }

In VScode, if will use the function by passing the wrong param, we will get error in IDE.

shouldBeNumber("100");

 

But this doesn‘t stop the compiler, the code will still be compiled without error.

 

[TypeScript] Type check JavaScript files using JSDoc and Typescript 2.5

标签:use   with   sse   add   ict   java   install   vscode   esc   

原文地址:http://www.cnblogs.com/Answer1215/p/7499282.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!