Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

cjs-wrapper.d.ts drops all named exports and the Nylas class type under exports-map resolution

未关闭
#760 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript

调研方向

从 cjs-wrapper.d.ts、exports map 和 lib/types/nylas.d.ts 开始,比较 CommonJS 和 ESM 的类型入口点。使用 node16 和 bundler 解析运行提供的 t.ts 和 tsconfig.json,同时关闭 skipLibCheck;当 CommonJS 使用者能够保留具名 exports 和 Nylas 类类型且没有声明错误时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Describe the bug

cjs-wrapper.d.ts uses export =, so the export * from './lib/types/models/index.js' line above it has no effect. Any TypeScript config that resolves through the exports map with the require condition (moduleResolution node16, nodenext, or bundler with module: commonjs) loses every named export: NylasApiError, NylasSdkTimeoutError, NylasOAuthError, and all the model types. The default import also stops working as a type, because export = nylasExport where nylasExport is typeof Nylas exposes the constructor value, not the class.

The runtime wrapper is fine. require('nylas') does expose the error classes via the Object.assign. Only the typings are wrong.

This was masked under moduleResolution: node10, which ignores exports and reads the top-level types field (lib/types/nylas.d.ts). TypeScript 7 removed node10, so every CommonJS consumer hits this on upgrade.

To Reproduce

// t.ts
import Nylas, { NylasApiError, NylasSdkTimeoutError } from "nylas";
let client: Nylas | undefined;
{
  "compilerOptions": {
    "module": "node16",
    "moduleResolution": "node16",
    "target": "es2022",
    "types": ["node"],
    "skipLibCheck": true,
    "noEmit": true
  },
  "files": ["t.ts"]
}
$ npx -p [email protected] tsc -p tsconfig.json
t.ts(1,17): error TS2305: Module '"nylas"' has no exported member 'NylasApiError'.
t.ts(1,32): error TS2305: Module '"nylas"' has no exported member 'NylasSdkTimeoutError'.
t.ts(2,13): error TS2749: 'Nylas' refers to a value, but is being used as a type here. Did you mean 'typeof Nylas'?

Same result with moduleResolution: bundler + module: commonjs. Same result on TypeScript 5.9.3 with node16. Passes on 5.9.3 with moduleResolution: node10.

With skipLibCheck off, the wrapper itself reports TS2309: An export assignment cannot be used in a module with other exported elements, which is the root cause.

Expected behavior

CommonJS consumers get the same named exports and the same Nylas class type as ESM consumers.

One way to do it: keep export = but merge the named exports into it with a namespace, so the wrapper stays require-compatible and the names come back:

import NylasClass from './lib/types/nylas.js';
import * as models from './lib/types/models/index.js';

declare const nylasExport: typeof NylasClass & typeof models;
export = nylasExport;

plus a declare namespace or type Nylas = NylasClass so the default import works as a type. Happy to open a PR if you want one.

SDK Version:

8.4.0 (also present on main as of today)

Additional context

Node 22, TypeScript 7.0.2 and 5.9.3.

主要语言
TypeScript
星标
180
派生
126
平均合并
4 天 6 小时
30 天内合并 PR
3

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nylas/nylas-nodejs 的其他 Issue

查看 nylas/nylas-nodejs 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。