GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Guidance on writing declaration file for multi-targeted libraries · Issue #4337 · microsoft/TypeScript Closed Labels @typesRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedCommittedThe team has roadmapped this issueThe team has roadmapped this issueSuggestionAn idea for TypeScriptAn idea for TypeScript DescriptionIt is now possible for a library to hit every type of target that TypeScript supports (module, namespace, and ES6). Currently, writing a declaration file for a library like this can be very challenging. The default today is something like this: declare namespace MyLib { export ... } declare module 'mylib' { export = MyLib; } This has a couple issues:
In the past, regarding item 1, it's been suggested that we split the declarations into two files (one for modules and one for namespaces). This makes sense. I think it also makes sense to extend that concept for ES6 modules. So if you have a library that targets all three, then you will have three mutually exclusive declaration files. Where things then become problematic is with duplicating the declarations in each file (which ideally should not happen). It is impossible to import an ambient module into an ambient namespace. It is possible to use an ambient namespace in an ambient module, but a naive approach to that (as shown in the common case above) violates item 1. Therefore, I propose this guidance to writing these declaration files. // mylib-common.d.ts declare namespace __MyLib { export ... } // mylib-namespace.d.ts /// <reference path="mylib-common.d.ts" /> import MyLib = __MyLib; // mylib-module.d.ts /// <reference path="mylib-common.d.ts" /> declare module 'mylib' { export = __MyLib; } // mylib-es6.d.ts /// <reference path="mylib-common.d.ts" /> declare module 'mylib' { export * from __MyLib; // this doesn't currently work, see #4336 export default __MyLib; // if there is a default export } Unfortunately this is currently hypothetical since you cannot re-export namespace declarations from an ES6 declaration. I'm proposing this as a baseline for discussion to solve this issue for good. It's possible I'm going down the wrong track or that there is already a better way to handle these cases. It would also be great if we could get some buy-in from the TypeScript language to solve this, if needed. Some possible ways TypeScript could be improved in this area:
Reacted by Michael Ledin Activity
MetadataMetadataAssigneesLabels@typesRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedCommittedThe team has roadmapped this issueThe team has roadmapped this issueSuggestionAn idea for TypeScriptAn idea for TypeScript TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |