- Ein Verzeichnis mit dem Namen „types in packets erstellt
- Eine package.json-Datei mit folgendem Inhalt erstellt:
Code: Select all
{
"name": "@repo/types",
"type": "module",
"private": true,
"exports": {
".": "./index.ts"
},
"version": "1.0.0",
"main": "./index.ts",
"types": "./index.ts",
"files": [
"./index.ts"
],
"scripts": {
"dev": "tsc --watch"
},
"devDependencies": {
"@types/node": "^20.8.10",
"body-parser": "^1.20.2",
"esbuild": "^0.19.5",
"tsx": "^3.14.0",
"typescript": "^5.5.4",
"@repo/typescript-config": "workspace:*"
},
"dependencies": {
"zod": "^3.22.4"
}
}
- Erstellt eine tsconfig.json-Datei:
Code: Select all
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../typescript-config/nextjs.json",
"compilerOptions": {
"outDir": "dist"
},
"include": [
"**/*.ts"
],
"exclude": [
"node_modules"
]
}
- Einige Typen zur Datei „packages/types/types/abc.ts“ hinzugefügt. Ich habe auch eine index.ts-Datei unter packets/types/ erstellt, um alles aus der Datei zu exportieren.
Code: Select all
typescript: Cannot find module '@repo/types' or its corresponding type declarations. [2307]
TS sollte den Fehler 2307 nicht anzeigen.
Ich habe das Paket „types“ hinzugefügt in einer Web-App wie folgt:
Code: Select all
"@repo/types": "workspace:*",
Code: Select all
import type { InventoryItem } from "@repo/types";