I would like developers to use a class or interface instead of directly importing functions.
Is there a way to restrict so only the class can import the function?
I prefer not to consolidate all the functions in a single file, especially in a large project where scalability is crucial.
For instance, I am trying to avoid this traditional pattern:
// myclass.ts
// excluding function exports
function foo(){ ... }
function bar(){ ... }
export class MyClass {
Foo(){ return foo() }
Bar(){ return bar() }
}
Here is the desired approach:
// foo.ts
export function foo(){ ... }
// I intend for this to be private while still being exported to be used by the class below
// bar.ts
export function bar() { ... }
// myclass.ts
import { foo } from 'foo';
import { bar } from 'bar';
export class MyClass {
Foo(){ return foo() }
Bar(){ return bar() }
}
// anyotherfile.ts
import { foo } from 'foo' // Prevent direct import
import { MyClass } from 'myclass' // Use this method instead