Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 12, 2025

The atsds-bnf npm package lacked TypeScript type definitions, preventing IntelliSense and type checking in TypeScript projects.

Changes

  • Manual declaration file: Created atsds_bnf/index.d.mts with proper type signatures for parse and unparse functions
  • Build configuration: Added rollup-plugin-copy to copy .d.mts file to dist/ during build
  • Package exports: Added types field to package.json pointing to dist/index.d.mts
  • Source preservation: Kept original index.mjs JavaScript implementation without TypeScript conversion

Result

TypeScript users now get proper type checking and autocompletion:

import { parse, unparse } from "atsds-bnf";

// Both functions are now properly typed: (input: string) => string
const ds = parse("a, b -> c");
const dsp = unparse("a\nb\n----\nc");

The declaration file is maintained manually and copied during build, keeping the implementation simple and straightforward while providing full TypeScript support.

[!WARNING]

Original prompt

This section details on the original issue you should resolve

<filter_complete></filter_complete>

<issue_title>给bnf下面的js包添加.d.mts</issue_title>

<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)

Original prompt

This section details on the original issue you should resolve

<issue_title>给bnf下面的js包添加.d.mts</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add .d.mts files for js package under bnf Add TypeScript declaration files to bnf package Dec 12, 2025
Copilot AI requested a review from hzhangxyz December 12, 2025 00:58
Copy link
Member

@hzhangxyz hzhangxyz left a comment

Choose a reason for hiding this comment

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

不是要你用ts重写你只需要补充一个d mts就行,然后rollup的时候copy过去,pakcage json里标注一下。

Copy link
Contributor Author

Copilot AI commented Dec 12, 2025

不是要你用ts重写你只需要补充一个d mts就行,然后rollup的时候copy过去,pakcage json里标注一下。

好的,已经改成简单的方式了。现在是:

  1. 保持 index.mjs 不变(不用 TypeScript 重写)
  2. 手动创建 index.d.mts 声明文件
  3. 用 rollup-plugin-copy 在构建时复制到 dist/
  4. 在 package.json 里添加了 types 字段

所有测试通过 ✓

Commit: 2d75afc

Copilot AI requested a review from hzhangxyz December 12, 2025 01:17
@hzhangxyz hzhangxyz marked this pull request as ready for review December 12, 2025 01:23
Copilot AI review requested due to automatic review settings December 12, 2025 01:23
Copilot AI and others added 5 commits December 12, 2025 09:24
Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
…plugin

Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
@hzhangxyz hzhangxyz force-pushed the copilot/add-dts-for-js-package branch from 2d75afc to 19f14ed Compare December 12, 2025 01:27
Copy link
Contributor

Copilot AI left a comment

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 adds TypeScript declaration files to the atsds-bnf npm package to provide type definitions for TypeScript users. The implementation follows the same patterns used in the parent atsds package by using .d.mts extension for ES module type definitions.

Key Changes

  • Created a manual TypeScript declaration file (index.d.mts) with properly typed signatures for parse and unparse functions
  • Configured the build pipeline to copy the declaration file to the distribution folder using rollup-plugin-copy
  • Updated package metadata to expose TypeScript types through the types field

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
bnf/atsds_bnf/index.d.mts New TypeScript declaration file with function signatures and JSDoc comments for parse and unparse functions
bnf/rollup.config.mjs Added rollup-plugin-copy plugin to copy declaration file to dist folder during build
bnf/package.json Added types field, included declaration file in files array, and added rollup-plugin-copy as dev dependency
bnf/package-lock.json Lockfile updates for rollup-plugin-copy and its transitive dependencies
bnf/atsds_bnf/.gitignore Updated to track both index.mjs and index.d.mts files (also corrected index.js → index.mjs)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hzhangxyz hzhangxyz merged commit 3b24d39 into main Dec 12, 2025
73 checks passed
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.

给bnf下面的js包添加.d.mts

2 participants