microsoft / microsoft/TypeScript

JSDoc import integration doesn't support return-style AMD modules

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

@sandersn đang làm issue này rồi.

Từ ngày 5/6/2020.

Awaiting More Feedback
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

TypeScript Version: 4.0.0-dev.20200508
also 3.8.3 (and presumably any other version)

Search Terms:
require, AMD, exports, import, JSDoc, module

Code

mod.js

// @ts-check

define(function () {
  // (1) this checks
  // exports.number = 12;

  // (2) this doesn't check
  // var exports = {
  //   number: 12
  // };
  // return exports;

  // (3) this also doesn't check
  return {
    number : 12
  }
});

usage.js

// @ts-check

define(function(require) {
  /** @type {import('mod')} */
  var Mod = require('mod');
  Mod.number;
});

My tsconfig is configured for JS/AMD/es5/noEmit:

    "allowJs": true,
    "module": "AMD",
    "target": "es5",
    "noEmit": true,

Expected behavior:

The import in the @type annotation in usage.js is correctly resolved for all three AMD module variants of mod.js .

Actual behavior:

Only the first variant, where number is explicitly added to exports works.
For the second and third variants, I get a compile error.

src/usage.js:4:23 - error TS2306: File 'd:/ns-prog/ts-jsdoc/src/mod.js' is not a module.

4     /** @type {import('mod')} */

Considering both (2) and (3) are valid AMD modules, I would expect this to work.

Note that JSDoc supports @exports annotation. Perhaps that could be utilized in the TypeScript-JSDoc integration?

Playground Link: N/A (I didn't see an option to have multiple files.)

Related Issues:
There's a StackOverflow question from 2016 https://stackoverflow.com/questions/37035462/importing-amd-modules-that-don-t-use-exports-with-typescript, but I didn't find any issue for it here.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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.

Đánh giá

Issue này chưa được đánh giá.

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.