【发布时间】:2020-09-08 15:23:03
【问题描述】:
例如在 Scala 中可以执行以下操作 (ScalaTest):
assertDoesNotCompile("val a: String = 1")
assertTypeError("val a: String = 1")
assertCompiles("val a: Int = 1")
TypeScript 世界中是否存在类似的东西?
编辑:
我的意思是上下文感知编译。例如来自这个问题的代码How do I write a scala unit test that ensures compliation fails?:
import shapeless.test.illTyped
//this version won't even compile
illTyped("getIdx(C.Ooga)")
//We can have multiple enum unions exist side by side
import Union_B_C._
B.values().foreach {b => Union_B_C.getIdx(b) should be (b.ordinal())}
C.values().foreach {c => Union_B_C.getIdx(c) should be (c.ordinal() + 2)}
//Though A exists in some union type, Union_B_C still doesn't know about it,
// so this won't compile
illTyped("""
A.values().foreach {a => Union_B_C.getIdx(a) should be (a.ordinal())}
""")
【问题讨论】:
标签: typescript assert