Publishing Typescript to NPM without including any JavaScript files

I want to publish my *.ts file on NPM, but it only contains type and interface definitions. There are no exported JavaScript functions or objects. Should I delete the "main": "index.js" entry in package.json and replace it with "main": "dist/types.ts" instead?

Do I need to compile my *.ts file to *.d.ts?

The types.js file includes:

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>)[] 
export type SingleOrDeepArray<T> = T|DeepArray<T>

export type Factory<T> = () => T
export type ProductOrFactory<T> = T|Factory<T>
export type ProductOrFactoryDeepArray<T> = (ProductOrFactory<T> | ProductOrFactoryDeepArray<T>)[] 

export type Dictionary<TValue> = { [key: string]: TValue }
export type ValueOf<TDictionary> = TDictionary[keyof TDictionary]
export type DictionaryOf<TDictionary> = Dictionary<ValueOf<TDictionary>>

Answer №1

If you're looking for inspiration, I recommend checking out examples on DefinitelyTyped (such as the @types/... packages).

After reviewing this information, it appears that:

  • "main" can be set as an empty string ("")
  • "types" should direct to your "index.d.ts"
  • Your package should not contain any *.ts files (only include *.d.ts files)

For further insight, you may find this resource helpful: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The filtering feature in the Row Group table of PrimeNG controls is malfunctioning and causing issues with the Dropdown

Within my Angular project, I have integrated PrimeNG controls version 11.4.4. Utilizing the Table control, I've structured tabular data to display rows in a grouped fashion with collapsible functionality. I've recently introduced a textbox and d ...

Setting text in a datetime picker with ngx-mat-datetime-picker in an Angular application is a straightforward process

I've been utilizing the ngx-mat-datetime-picker library from angular-material-components to enable datetime selection. It's functioning effectively, but I'm searching for a way to insert text preceding the hour and minute inputs, such as &ap ...

Localizing node modules is essential for enhancing performance and efficiency within

When it comes to working with modules already registered on NPM, the process of including them is quite simple: just run npm install <package> and then add var package = require('<package>') However, I am a bit unsure of how to get t ...

Having issues with TypeScript while using Redux Toolkit along with Next Redux Wrapper?

I have been struggling to find a solution. I have asked multiple questions on different platforms but haven't received any helpful answers. Can someone please assist me? Your help is greatly needed and appreciated. Please take some time out of your bu ...

The behavior of the npm i command varies depending on the version of Node being

I have the following dependencies listed in my package.json: "react": "^17.0.2", "react-dom": "^17.0.2", "react-split-pane": "^0.1.92", With the configuration below. $ node --version v12.22.1 $ n ...

Can a TypeScript file be created by combining a declaration file and a .js file?

It is commonly understood that declaration files are typically used for libraries rather than projects. However, let's consider a scenario where an existing JavaScript project needs to be migrated to TypeScript by creating d.ts files for each source ...

Preventing permission prompts when setting up a fresh React application

Whenever I attempt to create a new react app on my ubuntu os without using sudo, I encounter the following error message: Creating a new React app in /home/bunny/bunny. Installing packages. This might take a couple of minutes. Installing react, react-dom, ...

How to open a print preview in a new tab using Angular 4

Currently, I am attempting to implement print functionality in Angular 4. My goal is to have the print preview automatically open in a new tab along with the print popup window. I'm struggling to find a way to pass data from the parent window to the c ...

How to set up ReactJS on Ubuntu 18.04

Using Node.js curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - sudo apt-get install -y nodejs Updating npm to 5.3+ sudo npm install npm@latest -g Setting up Create-React-App npm install -g create-react-app create-react-app memory Afte ...

Establish an npm proxy by specifying the proxy server name without the need for the "http://" prefix

After successfully using npm a few times, I encountered an issue when trying to change my proxy settings. Previously, my configuration worked as follows: npm config get proxy: http://proxy-foo.foobar.com:8080 npm config get https-proxy: http://proxy-foo. ...

What is the process for exporting a class and declaring middleware in TypeScript?

After creating the user class where only the get method is defined, I encountered an issue when using it in middleware. There were no errors during the call to the class, but upon running the code, a "server not found" message appeared. Surprisingly, delet ...

Ensure that the database is properly configured before running any test suites

Currently, I am facing the challenge of seeding my database with all the necessary resources required to successfully test my API. These tests are spread across multiple files. Is there a method that will allow me to fully seed the database before any tes ...

Exploring the versatility of Angular 4 by implementing a switch feature with

My goal is to have the menu change based on the click of the "Cadastros" action, but it seems like the issue lies with the "workspaceSelected" property not being visible to all components. I believe the best approach in this situation would be to have the ...

When it comes to semantic versioning, which release number gets incremented when a module introduces compatibility improvements without causing any disruptions?

Recently, I encountered an npm module that was not working well with React 18 and Next.js. So, I took it upon myself to tweak certain aspects of the module to make it compatible with these packages. Thankfully, my modifications did not disrupt the experien ...

What is the best way to implement a switch case for the value of a property within an object in a TypeScript file?

The object I'm dealing with looks like this: {a: auth?.type === '1' || auth?.type === '2' || auth?.type === '3' ? { reason: // I need to implement a switch case here : un ...

React Material UI Select component is failing to recognize scrolling event

Having some difficulty understanding how to detect a scroll event with a Select component using Material-UI. The Select has MenuProps={...}, and I want to listen for the scroll event inside it. I've tried putting onScroll within MenuProps={...}, but ...

What is the syntax for creating ES6 arrow functions in TypeScript?

Without a doubt, TypeScript is the way to go for JavaScript projects. Its advantages are numerous, but one of the standout features is typed variables. Arrow functions, like the one below, are also fantastic: const arFunc = ({ n, m }) => console.log(`$ ...

Encountering an Issue with Dynamic Imports in Cypress Tests Using Typescript: Error Loading Chunk 1

I've been experimenting with dynamic imports in my Cypress tests, for example using inputModule = await import('../../__tests__/testCases/baseInput'); However, I encountered an issue with the following error message: ChunkLoadError: Loading ...

Async/await is restricted when utilizing serverActions within the Client component in next.js

Attempting to implement an infinite scroll feature in next.js, I am working on invoking my serverAction to load more data by using async/await to handle the API call and retrieve the response. Encountering an issue: "async/await is not yet supported ...

Issue with ambient contexts error in TypeScript constructor

What is the correct way to create a constructor in TypeScript? I have been researching and trying different approaches, but it seems like the syntax has changed. Here is my latest attempt: car.d.ts declare class Car { constructor(public engine: string ...