Quantcast
Channel: How to wrap an interface in an object while exporting it in TypeScript? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Tomáš Wróbel for How to wrap an interface in an object while exporting it in TypeScript?

$
0
0

Objects (every value in JavaScript / TypeScript) can contain only values as properties (methods, constants, properties) which interfaces are not. But don't worry, there's the way! Its name is namespaces.

export namespace a {   export interface x {      x: string;   }   export interface y{      x: string;   }}export namespace b {    export interface z {       x: string;    }    export interface i{       x: string;    }}

See TypeScript docs for more info.

Secondly

I recommend using ECMAScript modules, not CommonJS. If you use a normal TypeScript compiler, TypeScript automatically compiles to Node.js modules. You used it in the import but not in the export. Don't use export = {}. See TypeScript Docs for more.

In tsconfig.json:

{"compilerOptions": {        // ..."moduleResolution": "node","module": "commonjs"    }}

And then import {a, b} from "./x.ts"


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>