Skip to content

Ship real type declarations for botframework-directlinespeech-sdk - #6037

Open
Eugene (OEvgeny) wants to merge 5 commits into
mainfrom
OEvgeny/fix-directlinespeech-types
Open

Eugene (OEvgeny) wants to merge 5 commits into
mainfrom
OEvgeny/fix-directlinespeech-types

Conversation

@OEvgeny

@OEvgeny Eugene (OEvgeny) commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

botframework-directlinespeech-sdk ships JavaScript as its type declarations.

Changelog Entry

Fixed

  • Fixed botframework-directlinespeech-sdk shipping JavaScript as type declarations, and the createDirectLineSpeechAdapters return type naming webSpeechPonyfill instead of webSpeechPonyfillFactory, in PR #6037, by @OEvgeny

Description

tsup emitted the bundled JavaScript as the package's .d.mts/.d.ts, and the require types pointed to a never-built lib/index.d.ts: TypeScript consumers got wrong types (ESM) or none (CommonJS). The package now ships hand-written declarations for both. The bundle's createDirectLineSpeechAdapters type returns webSpeechPonyfillFactory, as at runtime, not webSpeechPonyfill.

Design

  • Hand-written index.d.ts rather than converting to TypeScript (1,700 lines) or generating from JSDoc (there is none, so all any).
  • tsup emits it as .d.mts and .d.ts: one src/index.d.ts for both conditions makes ESM types "masquerade as CJS" (arethetypeswrong).
  • The bundle keeps its as any: web-speech-cognitive-services' SpeechRecognition is not assignable to typeof SpeechRecognition.

Specific Changes

  • directlinespeech/src/index.d.ts: declarations for createAdapters and buildInfo; activities typed as interfaces are accepted

  • directlinespeech/tsup.config.ts: emits them

  • directlinespeech/package.json: require and top-level types point to dist/*.d.ts

  • directlinespeech/test-d/: tsd tests of the shipped declarations (options, result, buildInfo, invalid options), run by the "Type definitions test" job

  • bundle/src/createDirectLineSpeechAdapters.ts: webSpeechPonyfillFactory in the return type

  • bundle/test-d/pass/create-direct-line-speech-adapters.test-d.ts: checks it

  • I have added tests and executed them locally

  • I have added .changelog/<PR#>-<slug>.md

  • I have updated documentation

Review Checklist

This section is for contributors to review your work.

  • Accessibility reviewed (tab order, content readability, alt text, color contrast)
  • Browser and platform compatibilities reviewed
  • CSS styles reviewed (minimal rules, no z-index)
  • Documents reviewed (docs, samples, live demo)
  • Internationalization reviewed (strings, unit formatting)
  • package.json and package-lock.json reviewed
  • Security reviewed (no data URIs, check for nonce leak)
  • Tests reviewed (coverage, legitimacy)

@OEvgeny
Eugene (OEvgeny) marked this pull request as ready for review November 10, 2026 03:48
Copilot AI balanced review requested due to automatic review settings November 10, 2026 03:48

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@OEvgeny

Copy link
Copy Markdown
Collaborator Author

We should add tests with tsd like core and bundle do

"require": {
"types": "./lib/index.d.ts",
"types": "./dist/botframework-directlinespeech-sdk.d.ts",
"default": "./lib/index.js"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we move to tsup to build instead of Webpack?

How are we doing on bundle package?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think we should. A quick trial with one tsup config (ESM, CommonJS and the two IIFE browser scripts) replaced both Babel (lib/) and Webpack here: the browser scripts built in under a second, kept the same window.DirectLineSpeech exports, and the production one went from 613 KB to 500 KB. The catch is that require users would move from Babel's lib/ to tsup's CommonJS file, so it needs a real Direct Line Speech run before it ships. I'd rather keep this PR to the types and do that as the next one. It also lines this package up with the others for the tsdown move.

bundle already builds without Webpack (tsup, plus esbuild for static/) since #5329. Webpack is still used by directlinespeech, embed and the two isomorphic-react* packages.

@OEvgeny

Copy link
Copy Markdown
Collaborator Author

Added tsd tests in packages/directlinespeech/test-d/, set up like core's (test:tsd script, tsd config in package.json). They import the package by name, so they check the shipped dist/*.d.ts: fetchCredentials as a value, a promise or a function; the adapters, including posting an activity declared as an interface (like botframework-directlinejs's Activity); and buildInfo. Negative cases expect errors for a misspelled option, a missing fetchCredentials and audioInputDeviceId: 1. CI runs them in a new "Run tsd under packages/directlinespeech" step of the "Type definitions test" job (3477ecd).

This branch has not been deployed

No deployments
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.

3 participants