简体   繁体   English

TypeScript:如何指定内联对象的类型?

[英]TypeScript: How do you specify an inlined object's type?

I've got some code that compiles when I do this: 我这样做时会编译一些代码:

    const createCallback: any = {
        toBuffer: (func: any) => {
            return func();
        }
    };
    pdfCreateMock.returns(createCallback);

How do I get it to compile like this? 我如何获得像这样进行编译?

    pdfCreateMock.returns({
        toBuffer: (func: any) => {
            return func();
        }
    });

I don't know how to say that the inlined object is of type any . 我不知道怎么说内联对象是any类型的。 This is the error: 这是错误:

在此处输入图片说明

Cast to any 投射到任何

pdfCreateMock.returns(<any>{
        toBuffer: (func: any) => {
            return func();
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM