Declarations for a global library incorrectly interpreted as module
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 52/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- node.js, typescript
- 领域
- testing-qa, tooling
调研方向
使用所示的 index.d.ts 和 -tests.ts 文件运行 pnpm test 以重现故障,重点关注报告 "Masquerading as CJS." 的 node16 CJS 和 ESM 情况。将结果与 dtslint 0.0.199 进行比较,并检查相关的 dtslint 验证路径。当全局 StringLib 声明被接受且两个 ordinalize 断言都通过时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
I'm trying to add some types to the DefinitelyTyped repo for a very small, quite old JS library, which uses a simple global. I used dts-gen to create the project after cloning the DT repo, and I believe the structure and setup is correct.
The library looks like this:
"use strict";
(function () {
if (window && !window.StringLib) {
const suffixes = new Map([
['1', 'st'],
['2', 'nd'],
['3', 'rd'],
]);
window.StringLib = {
version: '1.0.0',
ordinalize: function (ordinal) {
const o = '' + ordinal;
const numFormat = parseInt(o, 10);
if (!o || !numFormat || numFormat < 0)
return '';
const last = o.at(-1) ?? '';
return o + (suffixes.get(last) ?? 'th');
},
};
}
}());
The index.d.ts for this library, which I believe is correct according to the TS documentation, is as follows:
/**
* @name StringLib
* @description Simple global string utilities
*/
declare namespace StringLib {
/**
* version
* @description The version of the library
*/
const version: '1.0.0';
/**
* ordinalize
* @param {string|number} ordinal The number to ordinalize
* @returns {string}
*/
function ordinalize(ordinal: string|number): string;
}
My -tests.ts file is as follows:
StringLib.ordinalize('1'); // $ExpectType string
StringLib.ordinalize(1); // $ExpectType string
I can see the types and JSDoc descriptions from the index.d.ts when I hover on the library or method in the tests file. However, when I use pnpm test the tests fail and node16 (cjs and esm) both show "Masquerading as CJS".
The exact same library, index.d.ts file, and tests used to work in dtslint version 0.0.199.
I've tried running the tests from the root of the DT repo, and also from in the types folder.
Is this a bug with dtslint? Or am I doing something wrong?
- 主要语言
- TypeScript
- 星标
- 422
- 派生
- 238
- 平均合并
- 1 天 4 小时
- 30 天内合并 PR
- 8
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/DefinitelyTyped-tools 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 66/100
microsoft/DefinitelyTyped-tools#1324 · 8 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 32/100
microsoft/DefinitelyTyped-tools#1230 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 42/100
microsoft/DefinitelyTyped-tools#1229 ·
维护者通常 1 天内回复
-
mergebot staleness comments do not respect tooManyOwners可能已有人在做 @copilot-swe-agent 于 322 天前认领。 未关闭
microsoft/DefinitelyTyped-tools#1218 · 1 个 reaction · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 45/100
microsoft/DefinitelyTyped-tools#1211 · 1 条评论 ·
维护者通常 1 天内回复
查看 microsoft/DefinitelyTyped-tools 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
umbraco/Umbraco-CMS-MCP-Dev#512 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
wimpysworld/sidra#290 ·
维护者通常 1 天内回复
-
defuFn invokes function values for inherited default properties可能已有人在做 @xiehuanyi 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 85/100
-
feature request good first issue
难度 2/5 1-3 小时 新手友好度 85/100
TabularisDB/tabularis#853 ·
维护者通常 1 天内回复
-
难度 2/5 1 小时以内 新手友好度 85/100
capricorn86/happy-dom#2474 ·
维护者通常 2 天内回复