I'm creating a library where I want to autogenerate Typescript types for the user's code. For that I would love to put the type definitions in a different folder, so that they are out of sight, but the IDE can still pick them up.
This is possible with Typescript modules, but I couldn't find a way to define types for an "ambient" module. A simplified code example for how I would like the file structure to be:
// src/pages/WelcomePage.ts
export const message = 'hi'
// src/index.ts
import { message } from './pages/WelcomePage'
console.log(message) // message should be of type "Message", not of type "string".
// types/pages/WelcomePage.d.ts
// This doesn't work.
// Can we make it work somehow?
declare module "pages/WelcomePage" {
type Message = string
export const message: Message
}
tldr: I would like all my generated types to be in types/... and they should define types for src/....