How can you define the full signature of a Typescript's file exports on the file itself?
Consider the following example:
// Example.ts
export async function getExample() {
const response = await fetch('/example');
return response.text();
}
export const mode = 'development';
// Specs.ts
export type Feature = {
getExample: () => Promise<string>;
mode: string;
}
Is there a way to import the Feature
type from Specs.ts
into Example.ts
in a manner that only needs to be declared once? Instead of:
import { Feature } from './Specs.ts';
// Example.ts
export async function getExample() {
const response = await fetch('/example');
return response.text();
} as Feature.getExample;
export const mode = 'development' as Feature.mode;
Is it possible to achieve:
import { Feature } from './Specs.ts';
type ThisFileExports = Feature;
export async function getExample() {
const response = await fetch('/example');
return response.text();
}
export const mode = 'development';