标题听起来可能不是很清楚,所以这里有一段代码。
class UserService {
static async findNumber(): number {
return await new Promise<number>((res) => setTimeout(() => res(1)}, 1000));
}
}
上面的代码生成了Type 'number' is not a valid async function return type in ES5/ES3 because it does not refer to
我正在编写TypeScript,并希望创建类似于Exclude<void, Promise<void>>的东西,它允许void,但不允许Promise<void>。
type A = (a: number) => Promise<void>
type B = (a: number) => void
declare let a: A
declare let b: B
// it does not cause type error
b = a
// what i want to do...
// but it is identical
我会使用fallback: 'blocking',作为我的Next.js页面,但是TypeScript拒绝了。拥有最新的12.2.0 Next.js。怎么啦?
Type '() => Promise<{ paths: any; fallback: string; }>' is not assignable to type 'GetStaticPaths<ParsedUrlQuery>'.
Type 'Promise<{ paths: any; fallback: string; }>'
我有这样的方法:
isOnPage(): Promise<boolean> {
return this.subtitle.isPresent();
}
类型记录编译器给出了以下错误:
Type 'webdriver.promise.Promise<boolean>' is not assignable to type 'Promise<boolean>'
有办法将WebDriver承诺转换为本地承诺吗?
这个能行吗?
isOnPage(): Promise<boolean> {
return new Pro
这是的扩展
鉴于这一守则:
class Animal {
a: string;
}
class Dog extends Animal {
b: string;
}
class Foo<T>{}
function test<T,A extends Dog>(animal:A, func: (p: A) => T): T;
function test<T,A extends Animal>(animal:A, func: (p: A) => Foo<T>): Foo<T>;
function test&l
我目前正在尝试实现一个以base64格式缓存文档的服务。我希望这个服务从sessionStorage中获取一个文档,如果sessionStorage中没有文档,那么从IRequestService获取它,然后保存到sessionStorage中。我尝试过这种方法,但是我得到了一个类型错误。
Type 'Promise<void | GetDocumentResult>' is not assignable to type 'Promise<GetDocumentResult>'.
代码如下所示:
getDocument(requestId
我已经创建了一个类来批量处理promises,并根据给出的键返回结果。例如,如果您给它两个名为order和customer的键,每个键都有一个promise,它将解析这些promise并返回一个对象,其中这些键作为属性,解析的值作为它们各自的值。
下面是这个类的用法:
const batchPromiseHandler = new BatchPromise();
// getCustomerInfo and getPaymentInfo will give back a promise which resolves into their data
batchPromiseHandler.a
我遵循了官方的Redux指南来创建我的thunk操作创建器,这样我就可以在我的react组件中使用绑定的操作。但是,我的组件不能识别函数返回promise,所以我不能使用then,这也意味着我不能访问函数的返回值。 以下是我的操作创建器代码示例: // Temp State for now, not important
type IAppState = any;
// Just a sample response object
interface ISampleThunkResponse {
text: string;
active: boolean;
}
// Thunk ac
React.useEffect(_ => {
ReactNativeAsyncStorage.getItem("jwt")
|> Js.Promise.then_(jwt => {Js.log(jwt)});
None;
});
错误:
This expression has type unit but an expression was expected of type
Js.Promise.t('a) = Js.Promise.t('a)
我在中使用
我正在将jQuery插件转换为使用promises而不是callbacks。这应该是非常基本的,但不确定问题是我在链接承诺中的方法、返回类型还是TypeScript只是过于挑剔。
我一直在犯这个错误:
Error 27 Supplied parameters do not match any signature of call target:
Type '(value: {}) => {}' requires a call signature, but type 'JQueryPromise<any>' lacks one.
我的
我使用的是Typescript 3.7断言签名,它们非常棒!但我也想在异步函数中使用它们,但我得到了一个错误:
Type 'void' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.
如果断言签名不能与异步函数一起工作,这将是有意义的,因为Typescript将需要评估Promise是否被解析,但我不确定是否有官方立场来支持它。