Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Declarations for a global library incorrectly interpreted as module

Đang mở
#1,192 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
node.js, typescript
Lĩnh vực
testing-qa, tooling

Hướng nghiên cứu

Tái hiện lỗi với các tệp index.d.ts và -tests.ts được hiển thị bằng cách chạy pnpm test, tập trung vào các trường hợp CJS và ESM của node16 báo cáo "Masquerading as CJS.". So sánh kết quả với dtslint 0.0.199 và kiểm tra đường dẫn xác thực dtslint liên quan. Hoàn tất khi các khai báo StringLib toàn cục được chấp nhận và cả hai assertion ordinalize đều pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
TypeScript
Star
422
Fork
238
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
8

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/DefinitelyTyped-tools

Tất cả issue của microsoft/DefinitelyTyped-tools

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.