What is the process for transitioning global reusable types to package types within turborepo?

When creating an app within the apps folder, a global.d.ts file is required with specific types defined like this:

interface Window{
    analytics: any;
}

This file should be designed to be reusable and placed in the packages/types directory for easy access across all apps.

After moving the Window type to packages/types, I encountered issues when trying to import these global types into my apps.

Answer №1

Properly setting this up requires following a few steps:

  1. To start, create a shared-types package within the packages directory of your monorepo
  2. Within the package.json file of the shared-types package, specify where the types are located:
{
    "name": "shared-types",
    "version": "1.0.0",
    "main": "./index.js",
    "types": "./index.ts",
    "dependencies": {
        "typescript": "latest"
      }
}
  1. Next, add the shared-types dependency to any applications that require it
 "dependencies": {
    ...
    "shared-types": "*"
  },
  1. Finally, import the necessary types into your project
import { MyType } from "shared-types";

For more detailed information, refer to the Sharing Code and Internal Packages sections in the Turborepo documentation.

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

Encountering an error in Nextjs with multer: TypeError when trying to read the property 'transfer-encoding' of undefined

Recently delving into Nextjs, I encountered an issue while attempting to upload a file using multer. The error message "TypeError: Cannot read property 'transfer-encoding' of undefined" popped up. The route requires authentication via auth middle ...

Issue with TypeScript problemMatcher "$tsc-watch" not actively monitoring files in VSCode

I'm attempting to avoid the necessity of using watch: true in my tsconfig.json setup. Despite utilizing VSCode's tasks with the default problem matcher $tsc-watch, I am encountering an issue where tsc is not running in watch mode during the buil ...

Issue with NullInjectorError: Failure to provide a custom component - Attempting to add to providers without success

I keep encountering errors during my test attempts... Despite looking into similar issues, I am still facing problems even after adding my custom LoginComponent to app.module.ts providers. It is already included in the imports section. app.module.ts @Ng ...

Issue encountered while attempting to utilize the useRef function on a webpage

Is it possible to use the useRef() and componentDidMount() in combination to automatically focus on an input field when a page loads? Below is the code snippet for the page: import React, { Component, useState, useEffect } from "react"; import st ...

The RxJs Observer connected to a websocket only triggers for a single subscriber

Currently, I am encapsulating a websocket within an RxJS observable in the following manner: this.wsObserver = Observable.create(observer=>{ this.websocket.onmessage = (evt) => { console.info("ws.onmessage: " + evt); ...

What's causing the subscription feature to malfunction in a fresh browser tab?

I am facing an issue with camera entries on an angular website. Whenever I click on an entry, a new window opens to display the camera livestream. However, I am having trouble with the subscribe functionality. Important note: Once the window is open, subs ...

Incorrect props being passed through useContext

I currently have my context Provider set up in my AppContext.tsx file. import { useState, useEffect, useContext, createContext } from 'react'; interface AppContextProps { children: React.ReactNode } const themes = { dark: { backgroundCo ...

Error: Failed to load chunk 552 due to chunk loading issue

Currently in the process of migrating Angular 12 to version 13. The migration itself was successful, however, upon running the project in the browser post a successful build, the application fails to display. On checking the console, I encountered the foll ...

Dealing with TSLint errors within the node_modules directory in Angular 2

After installing the angular2-material-datepicker via NPM, it is now in my project's node_modules folder. However, I am encountering tslint errors that should not be happening. ERROR in ./~/angular2-material-datepicker/index.ts [1, 15]: ' should ...

Assign a property to an array of objects depending on the presence of a value in a separate array

Looking to manipulate arrays? Here's a task for you: const arrayToCheck = ['a', 'b', 'c', 'd']; We have the main array as follows: const mainArray = [ {name:'alex', code: 'c'}, ...

Guide on implementing asyncWithLDProvider from Launch Darkly in your Next.js application

Launch Darkly provides an example (https://github.com/launchdarkly/react-client-sdk/blob/main/examples/async-provider/src/client/index.js) showcasing how to use asyncWithLDProvider in a React project (as shown below). However, I'm struggling to integr ...

How to properly define the _app.js and layout.tsx files in Next.js

Currently, I am working on a local application using next js and facing the challenge of distinguishing between the layout.tsx file and the _app.js file. The content in both files is quite similar, and I need help understanding how to differentiate them ef ...

Remove the main project from the list of projects to be linted in

Currently in the process of transitioning my Angular application to NX and have successfully created some libraries. I am now looking to execute the nx affected command, such as nx affected:lint, but it is throwing an error: nx run Keira3:lint Oops! Somet ...

Discovering a way to retrieve objects from an array of objects with matching IDs

Here is a code snippet I put together to illustrate my objective. arr = [ { id:1 , name:'a', title: 'qmummbw' }, { id:2 , name:'b', title: 'sdmus' }, { id:2 , name:'', title: 'dvfv' }, ...

"Time" for creating a date with just the year or the month and year

I am trying to convert a date string from the format "YYYYMMDD" to a different format using moment.js. Here is the code snippet I am using: import moment from 'moment'; getDateStr(date: string, format){ return moment(date, 'YYYYMMDD&a ...

Configuration file for collaborative component library within a Turbo repository

Currently, I am in the process of transitioning my Next.js application to a Turborepo monorepo structure and dividing the app's concerns into separate Next apps. Within this setup, there is a shared component library that will be utilized across all a ...

A guide on combining multiple arrays within the filter function of arrays in Typescript

Currently, I am incorporating Typescript into an Angular/Ionic project where I have a list of users with corresponding skill sets. My goal is to filter these users based on their online status and skill proficiency. [ { "id": 1, ...

Implement a class attribute to the parent <div> element using React and TypeScript

I'm trying to figure out how to achieve this task. I need to assign a class upon clicking on an element that is not directly in my code, but rather in one of its parent elements. My initial thought was to accomplish this with jQuery using the followi ...

Unable to upload to a gcloud signed URL from the client side using Next.js due to Error 403 Forbidden

After setting up a gcloud bucket with the correct permissions and creating a service account with the storage creator role, I developed a go backend to generate a signed url that successfully uploads files using a curl command. However, when attempting to ...

Does moment/moment-timezone have a feature that allows for the conversion of a timezone name into a more easily comprehendible format?

Consider this example project where a timezone name needs to be converted to a more readable format. For instance: input: America/Los_Angeles output: America Los Angeles While "America/Los_Angeles" may seem human-readable, the requirement is to convert ...