Typescript import/export

Mlouden

After running app.ts, I was expecting to get this result :

{ val: 'A' } //C
{ val: 'CONSTANT'} //B

but, I'm getting this result:

{ val: 'A' } //C
{ val: undefined } //B supposed to be 'CONSTANT' ??

Any ideas?? thank you !

This is the complete code:

tsconfig.json

"target": "es6",                                     
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"rootDir": "./src",
"outDir": "./dist", 
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,    
"strictPropertyInitialization": false,
"skipLibCheck": true 

app.ts

import { C } from "./second";
import { B } from "./first";

console.log(C)
console.log(B)

/**
 *  C depends on A
 *  B depends on CONSTANT
 **/

first.ts

import { CONSTANT } from "./second"
const A ={
    val: 'A'
}
const B = {
    val: CONSTANT
}
export { A, B }

second.ts

import { A } from "./first";
const CONSTANT = 'CONSTANT'
const C = {
    val: A.val
}
export { CONSTANT, C }
Dmitriybo

Here is a cyclic dependency. const CONSTANT = 'CONSTANT' should be placed in a separate file

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related