Typescript publicera till NPM utan JS
Hur publicerar jag min *.ts-fil till NPM som endast innehåller typ- och gränssnittsdefinition?
Det finns ingen exporterad JavaScript-funktion, objekt, etc.
Ska jag ta bort detta? "main": "index.js", -eller- ersätta med "main": "dist/types.ts",
Borde jag kompilera *.ts till *.d.ts?
filen types.js:
export type Optional<T> = T|null|undefined
export type OptionalOrFalse<T> = Optional<T|false>
export type SingleOrArray<T> = T|T[]
export type DeepArray<T> = (T|DeepArray<T>)[] // === T[] | T[][] | T[][][] | ...
export type SingleOrDeepArray<T> = T|DeepArray<T> // === T | T[] | T[][] | T[][][] | ...
export type Factory<T> = () => T
export type ProductOrFactory<T> = T|Factory<T>
export type ProductOrFactoryDeepArray<T> = (ProductOrFactory<T> | ProductOrFactoryDeepArray<T>)[] // === T[]|F[] | T[][]|F[][] | T[][][]|F[][][] | ...
export type ProductOrFactoryOrDeepArray<T> = ProductOrFactory<T> | ProductOrFactoryDeepArray<T> // === T|F | T[]|F[] | T[][]|F[][] | T[][][]|F[][][] | ...
export type Dictionary<TValue> = { [key: string]: TValue }
export type ValueOf<TDictionary> = TDictionary[keyof TDictionary]
export type DictionaryOf<TDictionary> = Dictionary<ValueOf<TDictionary>>
Svar #1
Jag skulle ta en titt på exempel från DefinitelyTyped (t.ex. @types/...-paket).
Baserat på detta, tror jag:
"main"kan vara en tom sträng ("")"types"bör peka på din"index.d.ts"- Ditt paket bör inte innehålla några
*.ts-filer (det bör innehålla*.d.ts-filer istället)
Detta kan också vara användbart att läsa igenom: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html