官术网_书友最值得收藏!

Questions

In order to cement what we have learned about TypeScript 3, have a go at the following questions:

  1. 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?

  1. 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?

  1. In your implementation of drawPoint, how can you make z in the point optional?
  1. 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?

  1. What build flag can we use to determine which projects are out of date and need to be rebuilt without doing a rebuild?
主站蜘蛛池模板: 留坝县| 和静县| 祁阳县| 永年县| 民和| 德昌县| 衡阳县| 东丽区| 池州市| 甘德县| 四会市| 拜泉县| 牡丹江市| 赤水市| 高尔夫| 东乡县| 西畴县| 嘉定区| 奉化市| 观塘区| 内黄县| 中方县| 团风县| 凤庆县| 闸北区| 商丘市| 托克逊县| 济宁市| 山阳县| 满洲里市| 肃南| 顺平县| 丹江口市| 莱州市| 淮安市| 民乐县| 嘉兴市| 瑞丽市| 巩义市| 剑阁县| 南召县|