Typescript primitive types: any difference between the types “number” and “Number” (is TSC case-insensitive)?

后端 未结 3 1757
太阳男子
太阳男子 2020-11-29 03:20

I meant to write a parameter of type number, but I misspelled the type, writing Number instead.

On my IDE (JetBrains WebStorm) the type

3条回答
  •  情话喂你
    2020-11-29 03:37

    To augment Ryan's answer with guidance from the TypeScript Do's and Don'ts:

    Don't ever use the types Number, String, Boolean, Symbol, or Object These types refer to non-primitive boxed objects that are almost never used appropriately in JavaScript code.

    /* WRONG */
    function reverse(s: String): String;
    

    Do use the types number, string, boolean, and symbol.

    /* OK */
    function reverse(s: string): string;
    

提交回复
热议问题