相关疑难解决方法(0)

打字稿:接口与类型

这些语句(接口与类型)之间有什么区别?

interface X {
    a: number
    b: string
}

type X = {
    a: number
    b: string
};
Run Code Online (Sandbox Code Playgroud)

typescript

516
推荐指数
16
解决办法
9万
查看次数

何时在TypeScript/Angular2中使用Interface和Model

我最近使用TypeScript观看了Angular 2的教程,但不确定何时使用接口以及何时使用模型来保存数据结构.

界面示例:

export interface IProduct {
    ProductNumber: number;
    ProductName: string;
    ProductDescription: string;
}
Run Code Online (Sandbox Code Playgroud)

型号示例:

export class Product {
    constructor(
        public ProductNumber: number,
        public ProductName: string,
        public ProductDescription: string
    ){}
}
Run Code Online (Sandbox Code Playgroud)

我想从URL加载JSON数据并绑定到接口/模型.有时我想要一个数据对象,其他时候我想要持有对象的数组.

我应该使用哪一个?为什么?

typescript angular

177
推荐指数
4
解决办法
10万
查看次数

The different between object and plain object in JavaScript?

Couldn’t understand the difference between object and plain object in JavaScript.

I know how Object looks like but don’t understand plain object. I googled about this but couldn’t understand.

As per my understanding normal object looks like below

  const object = {};
Run Code Online (Sandbox Code Playgroud)

Or we do call functions as objects in JavaScript

function test(){

}
Run Code Online (Sandbox Code Playgroud)

But what is plain object? how it differs with normal object. Thank you

Edit:

My confusion started about plain object after looking at below error. So …

javascript javascript-objects redux

5
推荐指数
3
解决办法
6795
查看次数

在Redux中将Class实例存储在何处以便可重用?

我正在尝试在我的React / Redux / redux saga应用中实现Pusher的消息传递库Chatkit,而我是Redux的新手。连接到chatkit的代码如下所示:

const chatManager = new ChatManager({
    instanceLocator: 'v1:us1:80215247-1df3-4956-8ba8-9744ffd12161',
    userId: 'sarah',
    tokenProvider: new TokenProvider({ url: 'your.auth.url' })
})

chatManager.connect()
    .then(currentUser => {
        console.log('Successful connection', currentUser)
    })
    .catch(err => {
        console.log('Error on connection', err)
    })
Run Code Online (Sandbox Code Playgroud)

我需要全局存储chatManager和currentUser对象(它们是具有功能的复杂类的实例),以便以后可以再次使用它们来加入房间,订阅事件等。

我最初的想法是我应该将其存储在Redux中,因为它现在是我的“全局存储”,但后来我意识到它可能无法工作,因为它不是我从存储中取出的原始对象,它将大概是一个克隆。然后我读到,显然只有普通对象应该存储在Redux中。

那么,那些不是普通对象但需要全局存储的对象又在哪里呢?我不想将它们放在window对象上,因为我可能会将其转换为React Native应用程序,而且看起来还是很混乱。

reactjs redux redux-saga

4
推荐指数
1
解决办法
2473
查看次数