Skip to content

Commit

Permalink
Add Helping with JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingwl committed Feb 22, 2020
1 parent 1a9b3c5 commit 36fbd87
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
@@ -1,38 +1,32 @@
//// { order: 3, isJavaScript: true }

// By default TypeScript doesn't provide error messaging
// inside JavaScript. Instead the tooling is focused on
// providing rich support for editors.
// 默认情况下,TypeScript 在 JavaScript 内不提供错误消息。
// 该工具专注于为编辑器提供丰富的支持。

// Turning on errors however, is pretty easy. In a
// typical JS file, all that's required to turn on TypeScript
// error messages is adding the following comment:
// 但是打开错误提示非常容易。在一个典型的 JS 文件中,只需要添加
// 以下注释即可打开 TypeScript 错误提示。

// @ts-check

let myString = "123";
myString = {};

// This may start to add a lot of red squiggles inside your
// JS file. While still working inside JavaScript, you have
// a few tools to fix these errors.
// 虽然在一开始可能会在您的 JS 文件中添加很多红色曲线。但是这仍然可以在
// JavaScript 中正常工作,并且有一些工具可以修复这些错误。

// For some of the trickier errors, which you don't feel
// code changes should happen, you can use JSDoc annotations
// to tell TypeScript what the types should be:
// 对于某些您不想修改代码的棘手的错误,您可以使用 JSDoc 注释来
// 告诉 TypeScript 类型应该是什么:

/** @type {string | {}} */
let myStringOrObject = "123";
myStringOrObject = {};

// Which you can read more on here: example:jsdoc-support
// 您可以在这里了解更多:example:jsdoc-support

// You could declare the failure unimportant, by telling
// TypeScript to ignore the next error:
// 您可以声明下一个错误是不重要的,以让 TypeScript 忽略下一个错误:

let myIgnoredError = "123";
// @ts-ignore
myStringOrObject = {};

// You can use type inference via the flow of code to make
// changes to your JavaScript: example:code-flow
// 您可以使用代码流进行类型推断来修改您的 JavaScript:example:code-flow
@@ -1,13 +1,11 @@
// TypeScript provides quick-fix recommendations for
// common accidents, they show up in your editor based
// on recommendations.
// TypeScript 为常见问题提供快速修复的建议,他们会基于这些建议
// 显示在编辑器中。

// For example TypeScript can provide quick-fixes
// for typos in your types:
// 例如,TypeScript 可以提供针对 typo 的快速修复:

const eulersNumber = 2.7182818284
eulersNumber.toStrang();
// ^______^ - select this to see the light build
// ^______^ - 选中这里查看效果

class ExampleClass {
method() {
Expand Down

0 comments on commit 36fbd87

Please sign in to comment.