回送4或打字稿不熟悉的语法

问题描述

我正在阅读回送4文档。我也已经阅读过打字稿教程。但是我没有这种语法:

module.exports = <ModelCrudRestApiConfig>{
  model: Product,pattern: 'CrudRest',// make sure to use this pattern
  dataSource: 'db',basePath: '/products',};

此符号是什么意思:

<Stuff>{ a: 1,c:2 }

也是这个

const ProductController = defineCrudRestController<
      Product,typeof Product.prototype.id,'id'
    >(Product,{basePath: '/products'});

从这里:https://loopback.io/doc/en/lb4/Creating-crud-rest-apis.html

也是来自回送还是来自打字稿?

谢谢

解决方法

这是Typescript类型断言(换句话说,您告诉编译器您比其更了解类型)。

基本上这是相同的,只是语法不同:

const stuff = <Stuff>{ a: 1,c:2 };

const stuff = { a: 1,c:2 } as Stuff;

此处有更多信息:https://basarat.gitbook.io/typescript/type-system/type-assertion