TypeScript type 和 interface 的区别
从使用的角度去看,这可能是个老生常谈的问题,就连 TypeScript 官方文档都会给你一个个介绍:
Interfaces vs Types in TypeScript
Documentation - Everyday Types
Learn about difference between Type & Interface in Typescript
具体来说(翻译成中文来说):
从使用的角度去看,这可能是个老生常谈的问题,就连 TypeScript 官方文档都会给你一个个介绍:
Interfaces vs Types in TypeScript
Documentation - Everyday Types
Learn about difference between Type & Interface in Typescript
具体来说(翻译成中文来说):
之前有一个奋斗了 N 小时才搞定的问题,在 Nestjs 的单元测试中反复测试会报类似于:
Starting Nest throws following error: Nest can't resolve dependencies of the EventResolver (EventService, ?). Please make sure that the argument at index [1] is available in the EventModule context.
Nest throws an error about a circular dependency that doesn't exist. Here is the error thrown:
Nest cannot create the module instance. Often, this is because of a circular dependency between modules. Use forwardRef() to avoid it. (Read more https://docs.nestjs.com/fundamentals/circular-dependency.) Scope [RootModule -> XXXModule]
最近 TypeScript 中毒,想想我一个弱类型出身的人,怎么就喜欢上了类型约束……当然这不是重点,重点可能还是 JS 没有接口,我没法靠 class 语法糖写的非常 OO……
关于 TS 的安利部分结束,今天我想说的其实是在 ts 中如何正确的 import json 格式。
首先我使用了基本姿势
import * as variable from './fooooooo.json'