小编Zen*_*Zen的帖子

如何在VS代码中使用TSLint?

我在VSCode中安装了TSLint并在tslint.json旁边创建了一个文件tsconfig.json.但是TSLint没有用.例如,我添加"curly": truetslint.json,但是当我编写没有花括号的if语句时,VS Code不会发出任何警告.这个扩展做了什么?

在此输入图像描述

typescript tslint visual-studio-code

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

如何在JavaScript/TypeScript中等待Promise列表?

我有以下的代码,fileStatsPromises是的Promise<Stats>[],无论是foobarPromise<Stats>[].等待他们的正确方法是什么?我想得到<Stats>[].

    const files = await readDir(currentDir);
    const fileStatsPromises = files.map(filename => path.join(currentDir, filename)).map(stat);

    const foo = await fileStatsPromises;
    const bar = await Promise.all(fileStatsPromises);
Run Code Online (Sandbox Code Playgroud)

编辑:一个最小的例子.

function makePromise() {
    return Promise.resolve("hello");
}
const promiseArray = [];
// const promiseArray = [] as Promise<string>[];
for (let i = 0; i < 10; i++) {
    promiseArray.push(makePromise());
}

(async () => {
    const foo = await promiseArray;
    const bar = await Promise.all(promiseArray);
})();
Run Code Online (Sandbox Code Playgroud)

截图

javascript async-await typescript ecmascript-next

20
推荐指数
1
解决办法
1万
查看次数

为什么忽略Chrome上被拒绝的承诺是错误的?

如果承诺被拒绝,我不想做任何事情getPromise().then(foo=>{});.为什么Chrome上出现错误?

(new Promise((resolve, reject)=>{reject()}))
Promise {[[PromiseStatus]]: "rejected", [[PromiseValue]]: undefined}
VM3250:2 Uncaught (in promise) undefined
Run Code Online (Sandbox Code Playgroud)

在Node和Firefox上,可以忽略被拒绝的部分.

javascript google-chrome

9
推荐指数
1
解决办法
5941
查看次数

如何将字符串对添加到rapidjson的文档中

我想使用rapidjson创建一个json字符串.但是我收到了一个错误:无法转换std::stringrapidjson::Type.

int x = 111;
string className = "myclass";

Document doc;
auto& allocator = doc.GetAllocator();

doc.AddMember("x", Value().SetInt(x), allocator);
doc.AddMember("className", className, allocator);

unordered_map<string, string>& map = sprite->toMap();
for (const auto& pair : map) {
    Value key(pair.first.c_str(), pair.first.size(), allocator);
    doc.AddMember(key, pair.second, allocator);
}

StringBuffer sb;
Writer<StringBuffer> writer(sb);

doc.Accept(writer);
log("json string: %s", sb.GetString());
Run Code Online (Sandbox Code Playgroud)

c++ json rapidjson

8
推荐指数
2
解决办法
8287
查看次数

如何在Qt/C++中创建属性绑定?

在QML中,很容易编写创建属性绑定,例如:

Rectangle {
    width: parent.width
} 
Run Code Online (Sandbox Code Playgroud)

是否可以在C++中执行此操作?

c++ qt qml

7
推荐指数
1
解决办法
2679
查看次数

无法在imith上将gif嵌入到github上的README.md中

我想在README.md上显示一个大的GIF.首先,我上传到imgur.然后,我将URL添加到README.md # <img alt="YAP" src="http://i.imgur.com/dNYswmI.gif">.但它无法加载,它被编译为:

<a href="https://camo.githubusercontent.com/b4f1167e599ce7936bb83aad5d007ca8f04345ac/687474703a2f2f692e696d6775722e636f6d2f644e5973776d492e676966" target="_blank">
    <img alt="YAP" src="https://camo.githubusercontent.com/b4f1167e599ce7936bb83aad5d007ca8f04345ac/687474703a2f2f692e696d6775722e636f6d2f644e5973776d492e676966" data-canonical-src="http://i.imgur.com/dNYswmI.gif" style="max-width:100%;"></a>
Run Code Online (Sandbox Code Playgroud)

这是我的README.

###Description
  A open source player.

###Screenshot
# <img alt="YAP" src="http://i.imgur.com/dNYswmI.gif">
Run Code Online (Sandbox Code Playgroud)

markdown github github-flavored-markdown

7
推荐指数
2
解决办法
7228
查看次数

使用Typescript和Mongodb时应如何定义文档的接口?

考虑一个简单的用户集合:

// db.ts
export interface User {
      _id: mongodb.ObjectId;
      username: string;
      password: string;
      somethingElse: string;
}

// user.ts
import {User} from "../db"
router.get("/:id", async (req, res) => {
    const id = req.params.id;
    // user._id is a mongodb.Object.
    const user: User = await db.getUser(id);

    res.send(user);
});

// index.ts
// code that will runs on browser
import {User} from "../../db"
$.get('/user/...').done((user: User) => {
    // user._id is string.
    console.log(user._id);
});
Run Code Online (Sandbox Code Playgroud)

直到我要在客户端代码中使用此接口之前,它都可以正常工作。因为_id当从服务器作为json传输时,用户的成为十六进制字符串。如果我设置_idmongodb.ObjectId | string,则行为会变得很奇怪。 在此处输入图片说明

mongodb typescript

6
推荐指数
1
解决办法
2855
查看次数

如何以编程方式更改 VSCode 的语言模式?

我努力了vscode.commands.executeCommand('workbench.action.editor.changeLanguageMode', 'JSON');。但它只是打开一个面板。并且TextDocument.languageId是只读属性。

typescript visual-studio-code vscode-extensions

5
推荐指数
2
解决办法
1110
查看次数

不是`QPoint`支持`std :: unique_ptr`?

我想存储QPoint在一个应该自动释放的对象中.

#include <QCoreApplication>
#include <memory>
#include <QPoint>

using namespace std;
class MyWidget{
public:
    vector<std::unique_ptr<QPoint>> _points;
    void f(QPoint point){
        std::unique_ptr<QPoint> pos(new QPoint(point));
        _points.push_back(pos);
    }
};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    MyWidget wid;
    wid.f(QPoint(0,0));

    return a.exec();
}
Run Code Online (Sandbox Code Playgroud)

错误消息是:

F:\ Qt\Qt5.5.0\Tools\mingw492_32\i686-w64-mingw32\include\c ++\ext \new_allocator.h:120:错误:使用已删除的函数'std :: unique_ptr <_Tp,_Dp> :: unique_ptr (const std :: unique_ptr <_Tp,_Dp>&)[with _Tp = QPoint; _Dp = std :: default_delete]'{:: new((void*)__ p)_Up(std :: forward <_Args>(__ args)...); } ^

这是否意味着我不应该unique_ptr用来存储QPoint

qt c++11

0
推荐指数
1
解决办法
163
查看次数

无法将缩略图按钮添加到窗口?

我正在尝试将缩略图按钮添加到窗口,但没有错误,也没有显示缩略图按钮.我阅读了以下页面以供参考:

  1. 您的第一个Windows程序 ;

  2. ITaskbarList3 :: ThumbBarAddButtons方法 ;

  3. github上的一些代码.

环境:win10 64bit,vs2015

// function WindowProc and wWinMain are copied from msdn directly.

#include "stdafx.h"
#include <windows.h>
#include "shobjidl.h" 
#include <exception>


LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

HRESULT addThumbnailButtons(HWND hwnd) {
    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
    if (SUCCEEDED(hr)) {
        ITaskbarList4* ptbl = nullptr;
        HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER,
            IID_PPV_ARGS(&ptbl));

        if (SUCCEEDED(hr)) {
            // create 2 buttons
            THUMBBUTTON thmb[2] = {};

            thmb[0].dwMask = THB_TOOLTIP;
            thmb[0].iId = …
Run Code Online (Sandbox Code Playgroud)

c++ windows winapi

0
推荐指数
1
解决办法
102
查看次数