zoukankan      html  css  js  c++  java
  • [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 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.

  • 相关阅读:
    uva11552
    zoj3820 树的直径+二分
    hdu 5068 线段树加+dp
    zoj3822
    uva1424
    DAY 36 前端学习
    DAY 35 前端学习
    DAY 34 PYTHON入门
    DAY 33 PYTHON入门
    DAY 32 PYTHON入门
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7499282.html
Copyright © 2011-2022 走看看