Declarations for a global library incorrectly interpreted as module
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- node.js, typescript
- Domain
- testing-qa, tooling
Research direction
Reproduce the failure with the shown index.d.ts and -tests.ts files by running pnpm test, focusing on the node16 CJS and ESM cases that report "Masquerading as CJS." Compare the result with dtslint 0.0.199 and inspect the relevant dtslint validation path. Done means the global StringLib declarations are accepted and both ordinalize assertions pass.
Written by the indexing model from the issue text.
Description
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?
- Dominant language
- TypeScript
- Stars
- 422
- Forks
- 238
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 8
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/DefinitelyTyped-tools
-
Difficulty 3/5 1-2 days Newbie friendliness 66/100
microsoft/DefinitelyTyped-tools#1324 · 8 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 32/100
microsoft/DefinitelyTyped-tools#1230 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
microsoft/DefinitelyTyped-tools#1229 ·
Maintainers usually reply within 1 day
-
mergebot staleness comments do not respect tooManyOwnersPossibly taken @copilot-swe-agent claimed this 321 days ago. Open
microsoft/DefinitelyTyped-tools#1218 · 1 reaction · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
microsoft/DefinitelyTyped-tools#1211 · 1 comment ·
Maintainers usually reply within 1 day
All issues in microsoft/DefinitelyTyped-tools
Similar issues
-
fix(data-lake): wizard source step still previews the local slug, not the server-disambiguated oneOpendata-lake
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
enhancement good first issue priority: low size: XS
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
-
bug ios mobile priority:P1
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
streamplace/streamplace#1351 ·
Maintainers usually reply within 2 days