简体   繁体   English

通常,static 种语言在编译时进行了类型检查。 typescript 是否也在编译时进行了类型检查?

[英]In general, static languages are type checked at compile time. Is typescript also type checked at compile time?

We create a TS file in vscode and report an error to us after deliberately writing a wrong type.我们在vscode中创建一个ts文件,故意写错类型后向我们报错。 Is the type checked at this time?这个时候检查类型了吗? We haven't done anything yet.我们还没有做任何事情。

So when did typescript start type checking?那么typescript是什么时候开始类型检查的呢?

Is TypeScript also type checked at compile time? TypeScript 是否也在编译时进行了类型检查?

Yes.是的。 In fact, other than a very small aspect related to enum s, TypeScript doesn't exist at runtime at all.事实上,除了与enum s 相关的一个非常小的方面,TypeScript 在运行时根本不存在。 TypeScript compiles to JavaScript, which is a dynamically-typed language. TypeScript 编译为 JavaScript,这是一种动态类型语言。

We haven't done anything yet.我们还没有做任何事情。 ... So when did typescript start type checking? ... 那么 typescript 是什么时候开始类型检查的呢?

VSCode, like many IDEs, will run TypeScript under the covers as you're working to type-check the code and report issues, which the IDE then reports to you.与许多 IDE 一样,VSCode 将在您进行类型检查代码和报告问题时在幕后运行 TypeScript,然后 IDE 会向您报告这些问题。 The IDEs run TypeScript in "no emit" mode (it doesn't produce its usual JavaScript output) so it's just doing syntax checking (because it has to to do its job) and type checking (its primary job). IDE 在“无发射”模式下运行 TypeScript(它不会产生通常的 JavaScript 输出)所以它只是进行语法检查(因为它必须完成它的工作)和类型检查(它的主要工作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Typescript对Vue进行道具检查 - Vue with Typescript type check of props on compile time 在Typescript中返回动态编译时间类型? - Return dynamic compile time type in Typescript? TypeScript:如何在编译时声明固定大小的数组以进行类型检查 - TypeScript: how to declare array of fixed size for type checking at Compile Time 打字稿编译时间错误 - Typescript compile time error 为什么在 TypeScript 中的“任意”字段类型变量上使用“字符串”函数时没有编译时错误? - Why there is no compile time error when 'string' functions are used on an 'any' field type variable in TypeScript? 为什么 typescript 中允许使用任何类型? 在编译时难以捕获错误的地方 - Why any type is allowed in typescript? where it makes difficult to catch error at compile time $('input [type = checkbox]:checked')。每个都不执行第二次 - $('input[type=checkbox]:checked').each not executing second time around 在单元测试松散类型语言时,是否应该检查返回类型的方法? - In unit testing loosely typed languages, should the return type of methods be checked? 返回联合类型,导致打字稿无法编译 - Return union type causing typescript not to compile 使用jquery检查javascript的静态/编译时间? - static/compile time check for javascript with jquery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM