Java资源分享网 - 专业的Java学习网站 学Java,上Java资源分享网
Learning TypeScript PDF 下载
匿名网友发布于:2024-09-02 09:58:51
(侵权举报)
(假如点击没反应,多刷新两次就OK!)

Learning TypeScript PDF 下载 图1

 

 

资料内容:

 

Freedom Through Restriction
TypeScript allows us to specify what types of values may be provided for parameters
and variables. Some developers find having to explicitly write out in your code how
particular areas are supposed to work to be restrictive at first.
But! I would argue that being “restricted” in this way is actually a good thing! By
restricting our code to only being able to be used in the ways you specify, TypeScript
can give you confidence that changes in one area of code won’t break other areas of
code that use it.
If, say, you change the number of required parameters for a function, TypeScript will
let you know if you forget to update a place that calls the function.
In the following example, sayMyName was changed from taking in two parameters
to taking one parameter, but the call to it with two strings wasn’t updated and so is
triggering a TypeScript complaint: