TypeScript入門與區塊鏈專案實戰(TypeScript Quickly)閱讀記錄
- 版本版次
- 錯誤記錄
- 翻譯
- 書中的總結
- 鏈接
首先感謝幾位譯者的辛苦付出,為了幫助后面閱讀這本書的更多人,將自己在閱讀程序中遇到的一些錯誤及讀起來不太通順或是費解的地方對比原版做出如下記錄, 一家之言,僅供參考,
版本版次
《TypeScript入門與區塊鏈專案實戰》
版次:2021年5月第1版
印次:2021年5月第1次印刷
《TypeScript Quickly》
錯誤記錄
p31:在發出的Java代碼中都不會有表示
修改:在發出的JavaScript代碼中都不會有表示
原文:Neither interfaces nor types declared with the type keyword have representations in the emitted JavaScript code, which makes the runtime code smaller (bytewise).
p33:應用正方形公式
修改:應用矩形公式
原文:Applies the formula for rectangles
p34 要解決這個問題,需要運行上述代碼
修改:要體驗這個問題,(可意譯為“可運行這部分代碼親自體驗”)
原文:To experience this issue, you need to run this code.
p34 只是isPerson()保護獲得一個錯誤物件作為引數
修改:除非isPerson()保護獲得一個錯誤物件作為引數
原文:This code has no compilation errors, and it works as expected unless the isPerson() guard gets a falsy object as an argument.
p41:然后通過使用static屬性和private屬性建構式,實作一個singleleton設計模式,
修改:然后通過使用static屬性和私有建構式,實作一個singleton設計模式,
原文:In this section we’ll look at a basic example, and then we’ll implement the singleton design pattern with the help of a static property and a private constructor.
p43:如圖3.3的第15行所示,我們呼叫sayHello()方法
修改:如代碼清單3.4的第15行所示,我們呼叫sellStock()方法
原文:原文本身的錯誤,
p46:2((CO5-3))
修改:2((CO5-3))
原文:原文本身的錯誤
p49:第1版的getProducts()函式(第4行)被第7行的第2個getProducts()替換
修改:第1版的getProducts()函式(第3行)被第7行的第2個getProducts()替換
原文:原文本身錯誤
p61:列舉——一種基于有限的值集合型別創建新型別的方式,
修改:列舉——一種基于有限的值集合型別 創建新型別的方式,(刪掉第一個“型別”)
原文:In this chapter, you’ll learn how to use enums—a way to create a new type based on a limited set of values.
p71:當泛型型別由函式引數指定時,不需要尖括號——在代碼清單4.9中可以看到該型別語法,
修改:當泛型型別由函式引數指定時,不需要尖括號——在代碼清單4.10中可以看到該型別語法,
備注:代碼清單4.9 未采用泛型型別的介面、代碼清單4.10 使用帶泛型型別的介面
interface Comparator <T> {
compareTo(value: T): number;
}
p71:字母T表示型別,這很直觀,但是任何字母或單詞都可用于宣告泛型型別,在圖中,開發者通常使用字母K表示鍵,V表示值,
修改:字母T表示型別,這很直觀,但是任何字母或單詞都可用于宣告泛型型別,在map集合中,開發者通常使用字母K表示鍵,V表示值,
原文:The letter T stands for type, which is intuitive, but any letter or word can be used when declaring a generic type. In a map, developers often use the letters K for key and V for value.
p132:為部署Web應用,我們通常系結源檔案以減少瀏覽器需要下載的檔案數量,
修改:為部署Web應用,我們通常打包源檔案以減少瀏覽器需要下載的檔案數量,
原文:To deploy a web app, we usually bundle up the source files to decrease the number of files the browser needs to download. Webpack is one of the most popular bundlers.
p:
修改:
原文:
todo
翻譯
p39:在后臺,JavaScript支持原型面向物件繼承
參考:Under the hood 怎么翻譯才地道?
原文:Under the hood, JavaScript supports prototypal object-based inheritance, where one object can be assigned to another object as its prototypethis happens at runtime.
p49:編譯過的JavaScript,方法(或函式)僅有一個函式體可以說明所有允許使用的方法引數,不過,TypeScript提供說明方法多載的語法,它歸結為宣告所有允許的方法簽名,但不用實作這些函式,緊跟后面提供執行方法(見代碼清單3.9),
參考:在編譯出的JavaScript中,方法(或函式)有且只能有一個函式體能夠處理所有的方法引數,不過,TypeScript為我們提供了用于定義方法多載的語法,簡言之,先宣告所有想要多載的方法簽名,不用提供實作,在這些簽名之后提供一個實作方法,
原文:In the compiled JavaScript, the method (or function) can have only one body that can account for all allowed method parameters. Still, TypeScript offers the syntax to specify method overloading. It comes down to declaring all allowed method signatures without implementing these methods, followed by one implemented method.


come down to sth
此處應該用的是第二種意思,所以不能翻譯為“它歸結為”,而應該理解為“簡而言之”之類的,
p67:聽起來很奇怪,型別能夠被引數化——你可以提供作為一種引數的型別(沒有值),
參考:聽起來或許有點奇怪,型別可以被引數化——你可以將型別(而不是值)作為引數來使用,
原文:Strange as it may sound, types can be parameterized—you can provide a type (not the value) as a parameter.
p71:保護開發者安全的網,
參考:保護開發者的安全網,
原文:Using type parameters is just a safety net for developers at compile time.
p81:TypeScript的enum關鍵字可用于定義常量的有限集合,
參考:TypeScript的enum關鍵字可用于定義一組有限常量集合,
原文:TypeScript has an enum keyword that can define a limited set of constants.
p83:你很想知道還有什么是有用的,在處理介面時,泛型及列舉尚不夠充分,
參考:你很想知道假設通過介面、泛型以及列舉這些方法不足以應對的時候還有哪些額外的手段,
原文:You’re curious to learn what else is available, as if dealing with interfaces, generics, and enums is not enough.
p106:看到同樣的自動完成工具和錯誤資訊提示,
參考:看到一致的自動補全及錯誤資訊提示,
原文:You’ll see the same autocomplete and error messages in the online TypeScript Playground, in Visual Studio Code, or in WebStorm.
p:
參考:
原文:
書中的總結
P51:如果你可以簡單地用引數型別和回傳值的union來實作的函式,為什么還要申明多載簽名?
答:函式多載有助于TypeScript編譯器能夠提供從引數型別到回傳值型別的合適的映射,當多載函式簽名被宣告后,TypeScript靜態分析器將適時地建議呼叫多載函式的可能方式,
P53:在我們日常的TypeScript編程作業中,幾乎很少使用多載,
鏈接
[1] 《TypeScript入門與區塊鏈專案實戰》之“使用TypeScript編程的理由”
[2] TypeScript從入門到專案實戰(進階篇)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/395724.html
標籤:區塊鏈
