- Learn React with TypeScript 3
- Carl Rippon
- 242字
- 2021-06-10 19:16:45
Questions
In order to cement what we have learned about TypeScript 3, have a go at the following questions:
- We have the following function, which draws a point:
function drawPoint(x: number, y: number, z: number) {
...
}
We also have the following point variable:
const point: [number, number, number] = [100, 200, 300];
How can we call the drawPoint function in a terse manner?
- We need to create another version of the drawPoint function, where we can call it by passing the x, y, and z point values as parameters:
drawPoint(1, 2, 3);
Internally, in the implementation of drawPoint, we draw the point from a tuple type [number, number, number]. How can we define the method parameter(s) with the required tuple?
- In your implementation of drawPoint, how can you make z in the point optional?
- We have a function called getData, which calls a web API to get some data. The number of different API resources is still growing, so we've chosen to use any as the return type:
function getData(resource: string): any {
const data = ... // call the web API
if (resource === "person") {
data.fullName = `${data.firstName} ${data.surname}`;
}
return data;
}
How can we make getData more type-safe by leveraging the unknown type?
- What build flag can we use to determine which projects are out of date and need to be rebuilt without doing a rebuild?
推薦閱讀
- 程序員面試筆試寶典(第3版)
- PHP基礎(chǔ)案例教程
- Learning Data Mining with Python
- Spring Boot+Spring Cloud+Vue+Element項目實戰(zhàn):手把手教你開發(fā)權(quán)限管理系統(tǒng)
- INSTANT Mercurial SCM Essentials How-to
- Learning Three.js:The JavaScript 3D Library for WebGL
- AppInventor實踐教程:Android智能應(yīng)用開發(fā)前傳
- PHP與MySQL權(quán)威指南
- Python滲透測試編程技術(shù):方法與實踐(第2版)
- Mastering Node.js
- Building Scalable Apps with Redis and Node.js
- Learning jqPlot
- Cocos2D Game Development Essentials
- Effective Python:編寫高質(zhì)量Python代碼的90個有效方法(原書第2版)
- Python編程零基礎(chǔ)入門