Skip to content

[api] Fix compatibility with older @types/node and exactOptionalPropertyTypes#4497

Merged
andrewbranch merged 2 commits into
microsoft:mainfrom
andrewbranch:api-fix-exact-optional-property-types
Jul 1, 2026
Merged

[api] Fix compatibility with older @types/node and exactOptionalPropertyTypes#4497
andrewbranch merged 2 commits into
microsoft:mainfrom
andrewbranch:api-fix-exact-optional-property-types

Conversation

@andrewbranch

Copy link
Copy Markdown
Member

Fixes #4405

Copilot AI review requested due to automatic review settings July 1, 2026 00:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses type-checking failures for consumers of the native-preview programmatic APIs when exactOptionalPropertyTypes: true is enabled and older @types/node versions are used, by tightening the package’s TS configuration and adjusting emitted/public API type shapes for optional properties and TextDecoder.

Changes:

  • Enable exactOptionalPropertyTypes for native-preview builds and relax test-only typechecking via skipLibCheck to accommodate third-party deps.
  • Update API surface typings so optional properties are compatible under exactOptionalPropertyTypes (e.g., explicitly allowing | undefined where required).
  • Add a local TextDecoder type to avoid relying on newer @types/node global type declarations.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
_packages/native-preview/tsconfig.base.json Enables exactOptionalPropertyTypes for the package.
_packages/native-preview/test/tsconfig.json Sets skipLibCheck for the test project (workaround for tinybench).
_packages/native-preview/src/ast/ast.ts Adjusts Node.jsDoc optional typing for exact-optional compatibility.
_packages/native-preview/src/api/sync/types.ts Updates optional properties to explicitly include `
_packages/native-preview/src/api/sync/api.ts Updates exported API surface and optional properties (generated sync API).
_packages/native-preview/src/api/node/node.ts Imports TextDecoder as a type from infrastructure module.
_packages/native-preview/src/api/node/node.infrastructure.ts Introduces a TextDecoder interface to support older @types/node.
_packages/native-preview/src/api/async/types.ts Updates optional properties to explicitly include `
_packages/native-preview/src/api/async/api.ts Updates optional properties to explicitly include `
Comments suppressed due to low confidence (1)

_packages/native-preview/src/api/sync/api.ts:121

  • src/api/sync/api.ts is marked as auto-generated from src/api/async/api.ts (see header and scripts/generateSync.ts). Adding __String to the sync export list without making the same change in the async source means the change will be lost the next time npm run generate:sync is run. Please add/adjust the export in src/api/async/api.ts (or add a sync directive) and regenerate the sync output.
export { CompletionItemKind, DiagnosticCategory, ElementFlags, ModifierFlags, ModuleKind, NodeBuilderFlags, ObjectFlags, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypePredicateKind };
export type { APIOptions, ClientSocketOptions, ClientSpawnOptions, DocumentIdentifier, DocumentPosition, LSPConnectionOptions, SourceFileMetadata };
export type { AssertsIdentifierTypePredicate, AssertsThisTypePredicate, BigIntLiteralType, BooleanLiteralType, CompletionEntry, CompletionInfo, CompletionOptions, ConditionalType, Diagnostic, FreshableType, IdentifierTypePredicate, IndexedAccessType, IndexInfo, IndexType, InterfaceType, IntersectionType, IntrinsicType, JSDocTagInfo, LiteralType, NumberLiteralType, ObjectType, StringLiteralType, StringMappingType, SubstitutionType, TemplateLiteralType, ThisTypePredicate, TupleType, Type, TypeParameter, TypePredicate, TypePredicateBase, TypeReference, UnionOrIntersectionType, UnionType };

Comment on lines +41 to +45
// The global type is not available in earlier @types/node versions
export interface TextDecoder {
decode(input?: ArrayBufferView | ArrayBufferLike): string;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wtf8.ts is not part of the public API so it doesn't enter a consumer's program

@andrewbranch andrewbranch added this pull request to the merge queue Jul 1, 2026
Merged via the queue into microsoft:main with commit 6ee18a2 Jul 1, 2026
21 checks passed
@andrewbranch andrewbranch deleted the api-fix-exact-optional-property-types branch July 1, 2026 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App using programmatic APIs fails to typecheck with exactOptionalPropertyTypes: true and @types/node v24

3 participants