Typing References in typescript are case sensitive?

纵然是瞬间 提交于 2021-01-28 23:14:22

问题


I use visual studio 2015 in a project with typescript and the files are named using lower and capital letters like this "project/Models/myFile.ts". When I want to import something from another module/file I use drag n drop in Visual studio so as to provide me automatically the reference with the path of the file, but it ignores capital letters and gives a path all in lowercase.

Question 1: Does this means that Visual studio is not case sensitive when referencing or importing files in typescript?

Question 2: Is it recommended to use all lowercase letters for naming folders and files, in order to be compatible with different Operating Systems?

UPDATE The path given in the reference comments /// <reference path="jquery" /> seems to be case insensitive so this /// <reference path="JQuery" /> works the same, but when using the import keyword, the path must much the exact naming of the file containing the module.


回答1:


Question 1: Does this means that Visual studio is not case sensitive when referencing or importing files in typescript?

It's case insensitive on Windows; however, I have found it's case sensitive at run-time only on some other operating systems like Linux. I ran into this problem one time when changing the casing standards in an application and everything worked fine until the code was run on the Linux CI.

In order to make code portable, it's important to make sure the casing in a module specifier matches the referenced file name exactly.

Question 2: Is it recommended to use all lowercase letters for naming folders and files, in order to be compatible with different Operating Systems?

This is a personal preference. For example, I prefer to make my file names have the same casing as the name of what is exported and this is what is recommend in some style guides. Some other people prefer to use kebab casing (ex. some-file-name.ts) while others prefer to use some other casing style.



来源:https://stackoverflow.com/questions/37617325/typing-references-in-typescript-are-case-sensitive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!