这是indexloc提供的服务,不要输入任何密码
Skip to content

@types/office-js: Word API - ListType appears as OneNoteApi, ListItemOrNull missing, and other list operation types incomplete for Word (with TS ^5.4.2, @types/office-js ^1.0.377) #72801

@icemouse0906

Description

@icemouse0906

Package: @types/office-js
Version: ^1.0.377
TypeScript Version: ^5.4.2
Target Office Application: Microsoft Word (Desktop) for macOS
Target WordApi Requirement Set in Manifest: 1.4

Problem Description:

I am developing a Microsoft Word Add-in using TypeScript. While most Office JS APIs are correctly recognized by TypeScript in my VS Code editor, I'm consistently encountering type errors related to Word's list formatting (bullets and numbering) APIs. Specifically, VS Code's TypeScript language service reports that it cannot find type definitions for key members like Word.ListType (for Word), Word.ListItemOrNull, and certain properties/methods on Word.ListItem and Word.List.

Interestingly, npm run build (using Webpack and ts-loader) compiles successfully without these type errors, but the editor experience is significantly hindered due to these persistent type-checking failures.

Observed Issues with Type Definitions in node_modules/@types/office-js/ (after full clean install with specified versions):
1.Word.ListType Enum:
When attempting to use Word.ListType.bullet or Word.ListType.number, the editor shows errors like "Namespace 'Word' has no exported member 'ListType'."

A search within the node_modules/@types/office-js/ directory for enum ListType reveals a definition, but its @remarks clearly state [Api set: OneNoteApi 1.1], not WordApi. No Word-specific ListType enum seems to be correctly exposed or defined.

// Found in @types/office-js (illustrative, actual path might vary within the package)
// declare namespace OneNote { // Or it might be in a more general namespace mistaken for Word's
// export enum ListType {
// /**
// * @remarks
// * [Api set: OneNoteApi 1.1]
// /
// None = "None",
// /
*
// * @remarks
// * [Api set: OneNoteApi 1.1]
// /
// Number = "Number",
// /
*
// * @remarks
// * [Api set: OneNoteApi 1.1]
// */
// Bullet = "Bullet",
// }
// }
2.Word.ListItemOrNull Interface:
When trying to access paragraph.listItemOrNullObject.isNullObject or call paragraph.listItemOrNullObject.delete(), the editor reports type errors (e.g., property 'isNullObject' does not exist on type 'never', or similar).

A search within node_modules/@types/office-js/ for interface ListItemOrNull yields no results, indicating this interface definition might be missing entirely for Word.
3.Word.ListItem Interface Members:

Accessing listItem.level or listItem.list (where listItem should be Word.ListItem) results in type errors.

While ListItemData and ListItemUpdateData (with level property, marked WordApi 1.3) are found, the core interface ListItem definition appears incomplete or its members are not correctly typed/exposed for direct use.
4.Word.List Interface Members:

Calling listItem.list.setListStyle(...) results in type errors.

The core interface List definition with a setListStyle(listType: Word.ListType): void; method (where listType is specifically Word.ListType) is not clearly found or correctly typed.
Project Configuration:

package.json (relevant devDependencies):
{
"devDependencies": {
// ... other dependencies ...
"@types/office-js": "^1.0.377",
"typescript": "^5.4.2"
}
}
tsconfig.json (compilerOptions):
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["dom", "ES2017", "ScriptHost"],
"strict": true,
"types": ["office-js", "node"],
"typeRoots": ["./node_modules/@types"],
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true
// ... other options ...
},
"include": ["src/**/*"]
}
Steps Taken to Troubleshoot (Persistent Editor Errors):

Performed a complete clean of the environment: deleted node_modules, package-lock.json, ran npm cache clean --force.
Ensured stable network (VPN active) and reinstalled dependencies (npm install after ensuring package.json reflects the versions above).
Verified and corrected tsconfig.json as shown above.
Restarted VS Code and TypeScript server multiple times.
Switched TypeScript versions used by VS Code (Workspace vs. VS Code's built-in).
Confirmed npm config get registry points to the official https://registry.npmjs.org/.
Crucially, after fresh installs, a thorough search within the new node_modules/@types/office-js/ still shows the ListType definition pointing to OneNoteApi and ListItemOrNull missing for Word.
Created a brand new yo office project (TypeScript, Word, Task Pane) and configured package.json and tsconfig.json to match the above. Migrated core configurations. The fresh project recognized basic types correctly. However, upon introducing the specific Word list API calls mentioned above, the same type errors reappear in the VS Code editor (while npm run build still succeeds)
Code Snippets Causing Editor Errors:

In a parser function:
TypeScript

// This line causes "Namespace 'Word' has no exported member 'ListType'."
// return { type: "ListStyle", value: Word.ListType.bullet };
In an applier function (assuming paragraph is Word.Paragraph):
TypeScript

// const paragraph: Word.Paragraph = target as Word.Paragraph;
// const value: any = instructionValue; // Value could be "none", or a Word.ListType enum

if (value === "none") {
// Error: Property 'listItemOrNullObject' does not exist on type 'Paragraph'.
// Or if it exists, 'isNullObject' or 'delete' might not be found on its type.
if (paragraph.listItemOrNullObject && !paragraph.listItemOrNullObject.isNullObject) {
paragraph.listItemOrNullObject.delete();
}
} else if (value === Word.ListType.bullet || value === Word.ListType.number) { // Error on Word.ListType
// Error: Property 'startNewList' does not exist on type 'Paragraph'.
const listItem = paragraph.startNewList();

// Error: Property 'level' does not exist on type 'ListItem' (or inferred type).
listItem.level = 0;

// Error: Property 'list' does not exist on type 'ListItem'.
// Or, if 'list' exists, property 'setListStyle' does not exist on type 'List'.
listItem.list.setListStyle(value as Word.ListType); // Error on Word.ListType if it gets that far
}
Expected Behavior:

VS Code's TypeScript language service should correctly recognize Word.ListType, Word.ListItemOrNull, and other standard Word list API members as defined in @types/office-js (version ^1.0.377), allowing for type-safe development and accurate IntelliSense without editor errors when using TypeScript ^5.4.2.

Actual Behavior:

VS Code editor shows persistent type errors indicating these Word-specific list API members are not found or incorrectly defined, despite npm run build succeeding. Manual inspection of the installed @types/office-js (version ^1.0.377) files suggests that the type definitions for Word's list API might indeed be incomplete, missing, or incorrectly referencing types from other Office applications (like OneNote's ListType).

Question for DefinitelyTyped Maintainers / Community:

Is this a known issue with @types/office-js version ^1.0.377 (or surrounding versions) regarding Word's List API type definitions when used with TypeScript ^5.4.2?
Are there specific steps or configurations I might be missing to ensure VS Code correctly loads and interprets these Word-specific types from this version of @types/office-js?
Could the WordApi 1.4 requirement set have an impact on how these types are exposed or defined in this version of @types/office-js?
Any guidance on how to resolve this discrepancy between the build process succeeding and the editor showing type errors for these standard APIs would be greatly appreciated.
Thank you for your time and help!
(This is my first time posting an issue like this here. If there are any breaches of etiquette or missing information, please let me know and I'll do my best to correct it. I've tried to be as thorough as possible based on my current understanding.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions