What is @microsoft/microsoft-graph-types?
@microsoft/microsoft-graph-types is an npm package that provides TypeScript type definitions for the Microsoft Graph API. This package helps developers to interact with Microsoft Graph API in a type-safe manner, ensuring that the data structures and API calls are correctly used.
What are @microsoft/microsoft-graph-types's main functionalities?
User Management
This feature allows you to define and manage user objects in a type-safe manner. The code sample demonstrates how to create a user object with specific properties.
const user: MicrosoftGraph.User = {
id: 'user-id',
displayName: 'John Doe',
mail: 'john.doe@example.com'
};
Calendar Events
This feature allows you to define and manage calendar events. The code sample demonstrates how to create an event object with specific properties such as subject, start time, and end time.
const event: MicrosoftGraph.Event = {
subject: 'Meeting',
start: {
dateTime: '2023-10-01T10:00:00',
timeZone: 'Pacific Standard Time'
},
end: {
dateTime: '2023-10-01T11:00:00',
timeZone: 'Pacific Standard Time'
}
};
Mail Management
This feature allows you to define and manage email messages. The code sample demonstrates how to create a message object with specific properties such as subject, body, and recipients.
const message: MicrosoftGraph.Message = {
subject: 'Hello World',
body: {
contentType: 'Text',
content: 'This is a test email.'
},
toRecipients: [
{
emailAddress: {
address: 'recipient@example.com'
}
}
]
};
Other packages similar to @microsoft/microsoft-graph-types
@microsoft/microsoft-graph-client
The @microsoft/microsoft-graph-client package provides a client library for making requests to the Microsoft Graph API. Unlike @microsoft/microsoft-graph-types, which focuses on type definitions, this package provides methods for making API calls and handling responses.
@pnp/graph
The @pnp/graph package is part of the PnPjs library and provides a fluent API for working with Microsoft Graph. It offers a more streamlined and fluent interface compared to @microsoft/microsoft-graph-types, which focuses on type definitions.

Microsoft Graph TypeScript Types
The Microsoft Graph TypeScript definitions enable editors to provide intellisense on Microsoft Graph objects including users, messages, and groups.
Installation
We recommend including the .d.ts file by downloading this package through npm.
npm install @microsoft/microsoft-graph-types --save-dev

Examples
The following examples assume that you have a valid access token. We used superagent to perform the HTTP requests, but you can use our JavaScript client library or other libraries as well.
import * as MicrosoftGraph from "@microsoft/microsoft-graph-types"
import * as request from 'superagent';
const accessToken:string = "";
List my recent messages
request
.get("https://graph.microsoft.com/v1.0/me/messages")
.set('Authorization', 'Bearer ' + accessToken)
.end((err, res) => {
if (err) {
console.error(err)
return;
}
let messages:[MicrosoftGraph.Message] = res.body.value;
for (let msg of messages) {
console.log(msg.subject);
console.log(msg.toRecipients[0].emailAddress.address);
}
})
Send an email as the logged in user
let mail:MicrosoftGraph.Message = {
subject: "Microsoft Graph TypeScript Sample",
toRecipients: [{
emailAddress: {
address: "microsoftgraph@example.com"
}
}],
body: {
content: "<h1>Microsoft Graph TypeScript Sample</h1>Try modifying the sample",
contentType: "html"
}
}
request
.post('https://graph.microsoft.com/v1.0/users/me/sendMail')
.send({message: mail})
.set('Authorization', 'Bearer ' + accessToken)
.end((err, res) => {
console.log(res)
})
Microsoft Graph beta support
If you want to test the Microsoft Graph beta endpoints, you can use those types simultaneously with the v1.0 types.
Update your package.json file with the following:
"devDependencies": {
"@microsoft/microsoft-graph-types": "^0.4.0",
"@microsoft/microsoft-graph-types-beta": "microsoftgraph/msgraph-typescript-typings#beta"
}
}
Import the beta types from @microsoft/microsoft-graph-types-beta
import {User as BetaUser} from "@microsoft/microsoft-graph-types-beta"
import * as MicrosoftGraphBeta from "@microsoft/microsoft-graph-types-beta"
Supported editors
Any TypeScript project can consume these types when using at least TypeScript 2.0. We've tested including the types as a dependency in the following editors.
Questions and comments
We'd love to get your feedback about the TypeScript definitions project. You can send your questions and suggestions to us in the Issues section of this repository.
Contributing
Please see the contributing guidelines.
Additional resources
Copyright
Copyright (c) 2017 Microsoft. All rights reserved.