Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"external types" for d.ts files dependent on others #1402

Closed
saschanaz opened this issue Dec 8, 2014 · 2 comments
Closed

"external types" for d.ts files dependent on others #1402

saschanaz opened this issue Dec 8, 2014 · 2 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Out of Scope This idea sits outside of the TypeScript language design constraints Too Complex An issue which adding support for may be too complex for the value it adds

Comments

@saschanaz
Copy link
Contributor

d.ts files on DefinitelyTyped frequently depend on other declaration files.

interface JSZipObject {
  name: string;
  dir: boolean;
  date: Date;
  comment: string;
  options: JSZipObjectOptions;

  asText(): string;
  asBinary(): string;
  asArrayBuffer(): ArrayBuffer;
  asUint8Array(): Uint8Array;
  //asNodeBuffer(): Buffer; <-- Disabled to prevent node.d.ts dependency
}

Bigger d.ts files depend on multiple big d.ts files, which again depend on others. (Example: atom.d.ts, ...) Collecting all those required files may not only be painful but also be unnecessary, especially for those who just want to use a specific part of a d.ts file that is not dependent on anything.

A method to specify external types can help here, allowing users to exclude unwanted declaration files.

// jszip.d.ts
/// <reference path="../node/node.d.ts" />
external interface Buffer: "../node/node.d.ts";

// use.d.ts
/// <referernce path="jszip.d.ts" />
var zip: JSZipObject;
var text = zip.asText(); // works fine without node.d.ts

var buffer = zip.asNodeBuffer(); // typeof any when there is no node.d.ts;
// No error but a warning: "interface Buffer should be defined by "node.d.ts"

interface Buffer { } may just work here, but not for classes as they are not open-ended.

// bar.d.ts
/// <reference path="foo.d.ts" />;
external class Foo: "foo.d.ts"; // This should not block Foo definition by foo.d.ts
interface Bar {
  foo: Foo;
}
@danquirk
Copy link
Member

danquirk commented Dec 8, 2014

This should be covered by ES6 module alignment. See the named import functionality like what's in 5.1 here http://www.2ality.com/2014/09/es6-modules-final.html We wouldn't want to do any TS specific syntax here that risks incompatibility with ES6+ versions.

@danquirk danquirk closed this as completed Dec 8, 2014
@danquirk danquirk added Too Complex An issue which adding support for may be too complex for the value it adds Out of Scope This idea sits outside of the TypeScript language design constraints Declined The issue was declined as something which matches the TypeScript vision labels Dec 8, 2014
@saschanaz
Copy link
Contributor Author

Thank you for the information! :)

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Out of Scope This idea sits outside of the TypeScript language design constraints Too Complex An issue which adding support for may be too complex for the value it adds
Projects
None yet
Development

No branches or pull requests

2 participants