Skip to content

Commit

Permalink
@mcap/support: remove .d.ts file in favor of module augmentation in s…
Browse files Browse the repository at this point in the history
…ource file (#1318)

### Changelog
@mcap/support: Fixed a TS error from an import that did not work in the
published package

### Docs

None

### Description

Supersedes / closes #1300 
See also protobufjs/protobuf.js#1499

This area of TypeScript arcana is confusing, but I don't think there is
anything about [module
augmentations](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation)
that requires them to be in a `.d.ts` file.

The way it's currently done was generally working, except as pointed out
in #1300 we didn't include the `typings` dir in the published package.

I believe we didn't run into this problem in our own code because we
usually turn on `"skipLibCheck": true`.
  • Loading branch information
jtbandes authored Jan 24, 2025
1 parent babc294 commit 2edefa7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 deletions.
14 changes: 0 additions & 14 deletions typescript/examples/bag2mcap/typings/protobufjs.d.ts

This file was deleted.

16 changes: 12 additions & 4 deletions typescript/support/src/protobufDescriptors.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../typings/protobufjs.d.ts" />

import protobufjs from "protobufjs";
import { FileDescriptorSet } from "protobufjs/ext/descriptor";
import { FileDescriptorSet, IFileDescriptorSet } from "protobufjs/ext/descriptor";

// https://github.com/protobufjs/protobuf.js/issues/1499
declare module "protobufjs" {
interface ReflectionObject {
toDescriptor(protoVersion: string): protobufjs.Message<IFileDescriptorSet> & IFileDescriptorSet;
}
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace ReflectionObject {
const fromDescriptor: (desc: protobufjs.Message) => protobufjs.Root;
}
}

export type ProtobufDescriptor = ReturnType<protobufjs.Root["toDescriptor"]>;

Expand Down
14 changes: 0 additions & 14 deletions typescript/support/typings/protobufjs.d.ts

This file was deleted.

0 comments on commit 2edefa7

Please sign in to comment.