forked from microsoft/TypeScript-Website
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
15 additions
and
23 deletions.
There are no files selected for viewing
28 changes: 11 additions & 17 deletions
28
packages/playground-examples/copy/zh/JavaScript/Helping with JavaScript/Errors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
10 changes: 4 additions & 6 deletions
10
packages/playground-examples/copy/zh/JavaScript/Helping with JavaScript/Quick Fixes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters