I apologize for being new to the js ecosystem. I work in a place where typescript is used, which is great because it helped me move from the background of static languages. However, I still do not understand the packaging / module system, especially when combined with typescript definitions.
I am writing a module with a bunch of interfaces describing the web service API contracts that will be used by the client library and the API service itself. If it was C # / Java or something, I would write my interface files, pack it, publish it, and it will be consumed by saying
import GetWizardsResponse from StuffInc.Contract.Wizards
This is how I approached my typescript library, so I wrote
export interface GetWizardsResponse {
wizards: Wizard
currentPage: number
count: number
}
Then in mine ts.config
I have "declaration": true
, so after tsc
I get a Wizards.d.ts
and Wizards.js
. When I npm publish
, I should use it, doing something like this:
import {GetWizardsResponse} from '@StuffInc/contracts/Wizards'
but when I look around, this is more common in such imports:
import * as Express from 'express'
or
import { Response, NextFunction } from 'express'
so I take it using my package should look like this:
import { GetWizardsResponse } from '@StuffInc/contracts
Thus, I have /wizards
, /goblins
, /elves
, but the import always comes from the `from @ StuffInc / contract '. What am I, what (what should I do right? All NPM packages look like this)
To do this, I realized that I needed to put everything in one file index.d.ts
. Can I write my code in logical separate files, but embed it in one definition so that other developers will not guess?