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

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[TypeScript] Type check JavaScript files using JSDoc and Typescript 2.5相关的知识,希望对你有一定的参考价值。

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

 

First of all, you should make sure you have [email protected] install:

sudo npm i -g [email protected]

 

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的主要内容,如果未能解决你的问题,请参考以下文章

vue-type-check: Vue 模板中的 Typescript 类型检查

写一下关于一些typescript的特性介绍视频

[LGP5115] Check,Check,Check one two!

spring security ajax登录

j_spring_security_check 404 JSF 登录错误

我在哪里可以找到“j_security_check”?