我有一个接收id的thunk,并在商店的特定区域上执行一些逻辑。然后我想在商店的一个完全不同的区域上做一些逻辑。要做到这一点,我不能触发一个常规的操作,因为我将无法访问商店:我需要另一个thunk。 export const thunkOne = ({ id }) => async (dispatch: Dispatch, getState) => {
const state = getState();
await dispatch(thunkTwo({ id }));
// ... do things with the state
return;
}; 现
我试图在TypeScript中创建一个类型化中介模式。该模式本身没有问题,但我希望在没有冗余的情况下完全输入它(不分别为命令注册和调度程序定义特定类型)。
这意味着,每当我这样做:
dispatchCommand({
type: "SAVE_EVIDENCE_EVALUATION",
command: {
// This gets autocompleted with the right typing
}
以下是我迄今所做的工作:
非类型化中介码
let commands = {};
export const registerCommand = ({ type, ha
当我在angular2 (typescript)中使用aws-sdk时,我得到了以下错误
import * as AWS from 'aws-sdk';
AWS.config.credentials.get
[ts]
Property 'get' does not exist on type 'Credentials | CredentialsOptions'.
Property 'get' does not exist on type 'CredentialsO
我有一个具有以下结构的JavaScript对象:
{
"_index": 1,
"foo": { ... },
"bar": { ... },
"baz": { ... },
}
也就是说,对象总是有一个带有数字值的属性_index,然后所有其他键(因为它被用作映射而没有定义)都有另一个特定对象的值。
我在TypeScript中尝试了以下类型
type Properties = {
_index: number
}
type Fields = {
// its not important what Me
在我的项目中,我将Scala代码转换为TypeScript代码。
现在,在Scala语言中有一个预先定义的类型,称为Option。选项意味着它可以是类型,也可以有未定义的类型。
在TypeScript中,我们通常是这样写的:
var myVar : MyType | undefined = await methodCall(...)
methodCall可以是这样的:
function methodCall(...) : Promise<MyType | undefined>
{
........
// The body of function
}
所以,现在我在Typ
假设我们有这样的代码:
class MyEvent {
timestamp:number;
}
class AEvent extends MyEvent{
x:number;
y:number;
}
class BEvent extends MyEvent{
key:string;
}
var fn:(event:MyEvent)=>void;
function AE(event:AEvent){
let x = event.x; //Ok, but BEvent hasn't 'x' property.
}
fn