I have a “models” folder in my app, that sits as a sibling alongside “components”, “services”, etc, and whenever I have a large and unique enough component or service I create a new file in “models” for it, and then create any/all custom typings I might need or of already used, so that in the application I can do FULL custom typing and not have to worry about using any primitives
Some of these files have up to at least a couple dozen exports, as I’ve been pretty thurough
Take a fully defined model for a bank account for example, an object with at least 10 distinct properties
Rather than just do this though…
export interface Account {
client: string,
number: number,
balance?: number,
social: number
…
}
I do it more like this…
though…
export type Name = string;
export type AccountNumber = number;
export type Currency = number;
export type USD = Currency;
export type Amount = USD;
export type Last4ofSSN = number;
export interface Account {
client: Name,
number: AccountNumber,
balance?: Amount,
social: Last4ofSSN
…
}
and so on…
So some of these files have quite a number of exports, like account.ts here in particular, and sometimes I need access in my code not just to the Account interface here, but to it’s individual property types as well
As a result, in one or two of my files, I’ve got an EXTREMELY length import call at the top, that’s just pulling in basic type declarations for me, it is long it wraps…
I’ve seen this working in the app with other particular tools, libraries, or whatever
import * from ‘…’;
or in some cases
import * as from ‘…’;
but these patterns aren’t working for me in my code, specifically with these “model” files
Instead, I have to be extremely specific, and double, triple down, etc in my import statement every time I write anything that handles an additional custom type, such as
import { Account, Name, AccountNumber, USD, Amount } from ‘@models/account’;
and so on…
I’ve seen the index.ts files used to prevent you from having to write out an entire path at the end of your import, but even then each individual item is still declared independently
Is it possible for me to just make
import * from ‘@models/account’;
and if so, how do I do that?