This is neither a bug nor a language feature suggestion, so I'm not sure if this is the right place.
I have been using TypeScript off and on for the past couple years. While the set of available type definitions has grown greatly over time, in almost every project I run into at least one library that requires me to write my own .d.ts. Every time I approach this problem I usually find myself spending half a day trying to figure out the correct syntax to get a 10-20 line .d.ts file working correctly. Each time I start with the TypeScript documentation, escalate to Google, and usually find myself reading through a dozen closed issues in the TypeScript GitHub repo, many of which are using syntax and techniques that are out of date.
I recognize that JavaScript is all over the place itself with regards to how libraries are authored (global, UMD, commonjs, AMD, ES6, TypeScript, etc.) and I find https://www.typescriptlang.org/docs/handbook/declaration-files/library-structures.html to be a great starting point for figuring out what kind of library I have. Unfortunately, once I figure out the type of library I have (Modular Library in my latest case) I feel like the docs kind of drop you without much guidance on where to go next.
If I click through to the next section of the handbook "By Example" I don't see anything talking about what to do with my "Modular Library" (in fact, Modular is nowhere on the page). There seems to be quite a bit about Globals there, but not much else. The same goes for the Deep Dive section, which has a ton of information but really no guide on how to create a definition file for my Modular Library. The problem here is that all I know at this point is that I have a "Modular Library" thanks to the "Library Structures" page. I don't know what of the gobs of information being presented to me is relevant for my use case.
If I keep clicking through to Templates I do see a few things named "module" something or other (that is kind of close to Modular), but they just show me the definition file, not the JavaScript file that the definition is for so I once again find myself unsure of which of the things I want. In my current case I have a JavaScript file that has module.exports = { foo: constructorFunction, bar: constructorFunction } and that doesn't seem to quite line up with any of the examples (though it is hard to say since the examples don't include any JavaScript).
Since there are so many different ways to setup JavaScript libraries, I think there would be value in having a small repository that has a bunch of different example JavaScript files with the type definitions sitting next to them (or perhaps in the same file for ease of comparison). I could try to browse through DefinitelyTyped, but there appear to be thousands of libraries in there and trying to find one that is "kind of similar to what I have" would take ages.
As far as the documentation itself goes, I think there would be great value in having a clear path forward for the reader once they have identified their library type. Right now it seems like the documentation for all of the different library types is jumbled together but in most cases a user is probably coming to the documentation with one library type they need to deal with, and seeing only documentation for that library type would greatly simplify the documentation I suspect.
This is neither a bug nor a language feature suggestion, so I'm not sure if this is the right place.
I have been using TypeScript off and on for the past couple years. While the set of available type definitions has grown greatly over time, in almost every project I run into at least one library that requires me to write my own
.d.ts. Every time I approach this problem I usually find myself spending half a day trying to figure out the correct syntax to get a 10-20 line .d.ts file working correctly. Each time I start with the TypeScript documentation, escalate to Google, and usually find myself reading through a dozen closed issues in the TypeScript GitHub repo, many of which are using syntax and techniques that are out of date.I recognize that JavaScript is all over the place itself with regards to how libraries are authored (global, UMD, commonjs, AMD, ES6, TypeScript, etc.) and I find https://www.typescriptlang.org/docs/handbook/declaration-files/library-structures.html to be a great starting point for figuring out what kind of library I have. Unfortunately, once I figure out the type of library I have (Modular Library in my latest case) I feel like the docs kind of drop you without much guidance on where to go next.
If I click through to the next section of the handbook "By Example" I don't see anything talking about what to do with my "Modular Library" (in fact, Modular is nowhere on the page). There seems to be quite a bit about Globals there, but not much else. The same goes for the Deep Dive section, which has a ton of information but really no guide on how to create a definition file for my Modular Library. The problem here is that all I know at this point is that I have a "Modular Library" thanks to the "Library Structures" page. I don't know what of the gobs of information being presented to me is relevant for my use case.
If I keep clicking through to Templates I do see a few things named "module" something or other (that is kind of close to Modular), but they just show me the definition file, not the JavaScript file that the definition is for so I once again find myself unsure of which of the things I want. In my current case I have a JavaScript file that has
module.exports = { foo: constructorFunction, bar: constructorFunction }and that doesn't seem to quite line up with any of the examples (though it is hard to say since the examples don't include any JavaScript).Since there are so many different ways to setup JavaScript libraries, I think there would be value in having a small repository that has a bunch of different example JavaScript files with the type definitions sitting next to them (or perhaps in the same file for ease of comparison). I could try to browse through DefinitelyTyped, but there appear to be thousands of libraries in there and trying to find one that is "kind of similar to what I have" would take ages.
As far as the documentation itself goes, I think there would be great value in having a clear path forward for the reader once they have identified their library type. Right now it seems like the documentation for all of the different library types is jumbled together but in most cases a user is probably coming to the documentation with one library type they need to deal with, and seeing only documentation for that library type would greatly simplify the documentation I suspect.