Reputation: 65
I'm working on a VSCode Extension. Part of the functionality is to get TodoTaskList from MS Graph. I'm currently using TypeScript version 4.3.5 and using the docs at https://github.com/microsoftgraph/msgraph-typescript-typings/, https://github.com/microsoftgraph/msgraph-sdk-javascript#2-create-a-client-instance and https://learn.microsoft.com/en-us/graph/api/resources/todo-overview?view=graph-rest-1.0
I am able to get accessToken using VS Code Authentication API and here's the code I wrote to get the TodoTaskList. I'm importing getMyTasks in extension.ts and passing the accessToken there.
import { Client } from "@microsoft/microsoft-graph-client";
import { AuthenticationProvider } from "@microsoft/microsoft-graph-client";
require('isomorphic-fetch');
import * as MicrosoftGraph from "@microsoft/microsoft-graph-types";
export async function getMyTasks(accessToken: string) {
class MyAuthenticationProvider implements AuthenticationProvider {
/**
* This method will get called before every request to the msgraph server
* This should return a Promise that resolves to an accessToken (in case of success) or rejects with error (in case of failure)
* Basically this method will contain the implementation for getting and refreshing accessTokens
*/
public async getAccessToken(): Promise<string> {
return accessToken;
}
}
const options = {
authProvider: new MyAuthenticationProvider(), // An instance created from previous step
};
const client = Client.initWithMiddleware(options);
try {
let taskList = await client.api("/me/todo/lists").get();
let tasks: [MicrosoftGraph.TodoTaskList] = taskList.value;
for (let task of tasks) {
console.log(task.displayName);
}
} catch (error) {
throw error;
}
}
Here's my dependencies from package.json:
"devDependencies": {
"@microsoft/microsoft-graph-types": "^1.41.0",
"@types/glob": "^7.1.3",
"@types/mocha": "^8.0.0",
"@types/node": "^14.0.27",
"@types/vscode": "^1.53.0",
"@typescript-eslint/eslint-plugin": "^4.1.1",
"@typescript-eslint/parser": "^4.1.1",
"eslint": "^7.9.0",
"glob": "^7.1.6",
"mocha": "^8.1.3",
"typescript": "^4.0.2",
"vscode-test": "^1.4.0"
},
"dependencies": {
"@microsoft/microsoft-graph-client": "^2.2.1",
"isomorphic-fetch": "^3.0.0"
}
I'm getting the following errors:
Upvotes: 0
Views: 1536
Reputation: 1
Setting a global type for that missing type will solve the problem
declare global {type RequestInfo = string | Request};
Upvotes: 0
Reputation: 65
This issue is acknowledged here: github.com/microsoftgraph/msgraph-sdk-javascript/issues/124
Fix: It needs lib: ["es6", "dom"]
in tsconfig.json
Huge thanks to @yume-chan
Upvotes: 2