内容简介:TypeScript 3.2 RC 发布了,主要更新内容包括: TypeScript 3.2 对 bind、call 和 apply 进行了更严格的检查 结合 TypeScript 2.0 中的 this 参数类型和 TypeScript 3.0 中的元组类型建模参数列表 ,可调用对象上...
TypeScript 3.2 RC 发布了,主要更新内容包括:
TypeScript 3.2 对 bind、call 和 apply 进行了更严格的检查
结合 TypeScript 2.0 中的 this 参数类型和 TypeScript 3.0 中的元组类型建模参数列表 ,可调用对象上的方法由名为 CallableFunction 的新全局类型描述,该类型声明了更严格的 bind、call 和 apply 签名版本。类似地,可构造(但不可调用)对象的任何方法都由名为 NewableFunction 的新全局类型描述。
Function.prototype.apply 在此行为下执行示例:
function foo(a: number, b: string): string {
return a + b;
}
let a = foo.apply(undefined, [10]); // error: too few argumnts
let b = foo.apply(undefined, [10, 20]); // error: 2nd argument is a number
let c = foo.apply(undefined, [10, "hello", 30]); // error: too many arguments
let d = foo.apply(undefined, [10, "hello"]); // okay! returns a string支持泛型对象 spread
// Returns 'T & U'
function merge<T, U>(x: T, y: U) {
return { ...x, ...y };
}
// Returns '{ name: string, age: number, greeting: string } & T'
function foo<T>(obj: T) {
let person = {
name: "Daniel",
age: 26
};
return { ...person, greeting: "hello", ...obj };
}支持泛型对象 rest
interface XYZ { x: any; y: any; z: any; }
type DropXYZ<T> = Pick<T, Exclude<keyof T, keyof XYZ>>;
function dropXYZ<T extends XYZ>(obj: T): DropXYZ<T> {
let { x, y, z, ...rest } = obj;
return rest;
}引入了一个名为 bigint 的新原始类型
let foo: bigint = BigInt(100); // the BigInt function
let bar: bigint = 100n; // a BigInt literal
// *Slaps roof of fibonacci function*
// This bad boy returns ints that are *so* big!
function fibonacci(n: bigint) {
let result = 1n;
for (let last = 0n, i = 0n; i < n; i++) {
const current = result;
result += last;
last = current;
}
return result;
}
fibonacci(10000n)declare let foo: number; declare let bar: bigint; foo = bar; // error: Type 'bigint' is not assignable to type 'number'. bar = foo; // error: Type 'number' is not assignable to type 'bigint'.
console.log(3.141592 * 10000n); // error console.log(3145 * 10n); // error console.log(BigInt(3145) * 10n); // okay!
function whatKindOfNumberIsIt(x: number | bigint) {
if (typeof x === "bigint") {
console.log("'x' is a bigint!");
}
else {
console.log("'x' is a floating-point number");
}
}JSX 解决方案变更
解决 JSX 调用的逻辑已与解析函数调用的逻辑统一,虽然这简化了编译器代码库并改进了一些用例,但可能需要协调一些差异。它们本身并没有破坏性变更,但是升级者应该关注遇到的问题。
详情查看发布公告。
【声明】文章转载自:开源中国社区 [http://www.oschina.net]
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- NutzCodeInsight 2.0 发布 重磅推出 NutzBoot 构筑中心
- TypeScript 3.2 发布,微软推出的 JavaScript 超集
- TypeScript 3.3 发布,微软推出的 JavaScript 超集
- TypeScript 2.8.4 发布,微软推出的 JavaScript 超集
- TypeScript 2.9.1 发布,微软推出的 JavaScript 超集
- TypeScript 2.9.2 发布,微软推出的 JavaScript 超集
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
深入浅出Struts 2
Budi Kuniawan / 杨涛、王建桥、杨晓云 / 人民邮电出版社 / 2009-04 / 59.00元
本书是广受赞誉的Struts 2优秀教程,它全面而深入地阐述了Struts 2的各个特性,并指导开发人员如何根据遇到的问题对症下药,选择使用最合适的特性。作者处处从实战出发,在丰富的示例中直观地探讨了许多实用的技术,如数据类型转换、文件上传和下载、提高Struts 2应用的安全性、调试与性能分析、FreeMarker、Velocity、Ajax,等等。跟随作者一道深入Struts 2,聆听大量来之......一起来看看 《深入浅出Struts 2》 这本书的介绍吧!