首页 > 其他分享 >typescript循环依赖error

typescript循环依赖error

时间:2022-12-30 16:12:35浏览次数:43  
标签:typescript const ts 依赖 export b1 error import a2

// a.ts
import { b } from "./b"
export const a = [b]
 
// b.ts
import { a } from "./a"
export const b = [a]

// a.ts
import { b1 } from "./b"

export const a1 = 123

export const a2 = [b1]

 
// b.ts
import { a2 } from "./a"

export const b1 = 312

export const b2 = [a2]


类似上述代码则会造成以下异常error

解决办法:

解开文件之间的循环依赖即可,切忌文件之间不可相互依赖

// a.ts
import { b1 } from "./b"

export const a1 = 123

export const a2 = [b1]

 
// b.ts
import { a2 } from "./a"

export const b2 = [a2]

// c.ts
export const b1 = 312

标签:typescript,const,ts,依赖,export,b1,error,import,a2
From: https://www.cnblogs.com/Kidrue/p/17015145.html

相关文章