Assume project structure below:
packages/
utilities/
index.ts
app/
app.ts
tsconfig.json
I created path aliases in order to access packages easier between each other, my tsconfig looks like this
{
"compilerOptions": {
"moduleResolution": "node",
"noEmit": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"isolatedModules": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"allowJs": false,
"noImplicitAny": true,
"strict": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"$app/*": ["packages/app/*"],
"$utilities/*": ["packages/utilities/*"],
}
},
"include": [
"packages/*"
]
}
Finally my packages/utilities/index.ts file is sort of a mid point that imports and exports all utils I want to expose i.e.
export { isValidEmail } from '$utilities/validators';
//... etc
I initially thought that my app package would be able to do something like this
import { isValidEmail } from "$utilities";
// Errors Cannot find module '$utilities' or its corresponding type declarations.
But it errors with message above unless I use full path $utilities/index

$utilities/*will be mapped to the corresponding directory, so just$utilitieswould have to be a separate entry if you want to import it that way. Someone might be able to give a cleaner solution but I think that's just the way it works.