1、字符串转对象
//将js对象转化为JSON字符var obj2 = JSON.parse(str1);
2、对象转字符串
var jsonstr = JSON.stringify(jsonObject);
这里使用&
可以实现类似的效果,如下:
interface Foo {a: string;}type Bar = Foo & {b: number;};
https://blog.51cto.com/15077562/2608878
常用语法:
Omit去掉Partial可选keyofPick选取extends 继承Dictionary&Many
下面是常用的,详细的请看
改变变量名
let node = {type: 'Identifier',name: 'foo',};let { type: localType, name: localName } = node;console.log(localType); // "Identifier"console.log(localName); // "foo"
默认值
let node = {type: 'Identifier',name: 'foo',};let { type, name, value = true } = node;console.log(type); // "Identifier"console.log(name); // "foo"console.log(value); // true
嵌套对象解构
let node = {type: 'Identifier',name: 'foo',loc: {start: {line: 1,column: 1,},end: {line: 1,column: 4,},},};let {loc: { start },} = node;console.log(start.line); // 1console.log(start.column); // 1
const groupId = Number(id);const groupId = id as number;//下面的在tsx中不能使用const groupId = <number>id;