1

我正在尝试创建一个新的 JsonPatchDocument 如下,

让 PatchDoc = new JsonPatchDocument();

但是以上是不可能的,因为 JsonPatchDocument 是打字稿中的一个接口。任何人都可以帮助如何做到这一点???

我使用 let PatchDoc 创建: JsonPatchDocument;

如果这样做,我将无法将数据添加到 JsonPatchDocument PatchDoc .add( { op: "add", path: "/fields/System.Priority" , value: "1" })

它说在类型 JsonPatchDocument 上不存在 add

4

1 回答 1

-1

请参阅下面的代码:

import * as vm from 'vso-node-api/WebApi';
import * as wa from 'vso-node-api/WorkItemTrackingApi';
import * as wi from 'vso-node-api/interfaces/WorkItemTrackingInterfaces';
import * as vss from 'vso-node-api/interfaces/Common/VSSInterfaces';

var collectionUrl = "https://xxxxxx.visualstudio.com";

let token: string = "Yourpersonalaccesstoken";

let creds = vm.getPersonalAccessTokenHandler(token);

var connection = new vm.WebApi(collectionUrl, creds); 

let vstsWI: wa.IWorkItemTrackingApi = connection.getWorkItemTrackingApi();

async function getWI() {
    let wiid: number = 1;
    let workitem: wi.WorkItem = await vstsWI.getWorkItem(wiid);

    console.log(workitem.url);
}

getWI();

async function createWI() {
    let wijson: vss.JsonPatchDocument = [{ "op": "add", "path": "/fields/System.Title", "value": "Task created from Node JS" }];
    let project: string = "Project";
    let witype: string = "Task";
    let cWI: wi.WorkItem = await vstsWI.createWorkItem(null, wijson, project, witype);
    console.log(cWI.id);
}

createWI();

相关问题:如何使用 Visual Studio Team Services Client for Node.js (vso-node-api) 创建工作项?

于 2018-03-16T08:14:12.843 回答