我有以下代码:
type Document = number | string | Array<Document>;
Run Code Online (Sandbox Code Playgroud)
TypeScript抱怨以下错误:
test.ts(7,6): error TS2456: Type alias 'Document' circularly references itself.
Run Code Online (Sandbox Code Playgroud)
显然不允许循环引用.但是,我仍然需要这种结构.这将是一个解决方法?
我正在构建一个小脚本,该脚本使用TypeScript Compiler API扫描具有给定类型成员的所有接口,其源代码可在此处找到。我检查这些类的成员,看看它们是如何相互关联的。
我的问题是:我怎么知道一种类型何时可以分配给另一种类型?我搜索了TypeChecker
一种方法,但找不到。有没有人有任何指示?这是一个应该能够分析的东西的例子:
export enum ASTKind {
Number,
Addition,
Multiplication,
}
export interface AST {
kind: ASTKind
}
export interface BinaryExpression extends AST {
left: AST
right: AST
}
export interface Addition extends BinaryExpression {
kind: ASTKind.Addition
}
export interface Multiplication extends BinaryExpression {
kind: ASTKind.Multiplication
}
Run Code Online (Sandbox Code Playgroud)
本质上,我想要一个谓词,说明是否ASTKind.Multiplication
可分配给ASTKind
(在这种情况下为真)。
我有一些类型实例.让我们称它们为A,B和C.它们都是类型类X的实例.现在我想创建一个单独的函数create
,在给定一些输入(比如说一个字符串)的情况下创建一个A,B或C的实例.类型系统无法知道输入什么类型的输入.这就是Haskell不喜欢的事情,我想我知道答案,但我想确定.我得到的当前错误是:
• Couldn't match expected type ‘c’ with actual type ‘GCCCommand’
‘c’ is a rigid type variable bound by
the type signature for:
compiler :: forall c. CompilerCommand c => String -> c
at src/System/Command/Typed/CC.hs:29:1-44
• In the expression: gcc path
In an equation for ‘compiler’:
compiler path
| exe == "g++" || exe == "gcc" || exe == "cc" || exe == "cpp"
= gcc path
where
exe = takeFileName path
• Relevant bindings include
compiler :: …
Run Code Online (Sandbox Code Playgroud) 我正在使用Elixir OptionParser
,但我在解析长的虚假参数时遇到了问题.
最好,我想做这样的事情:
OptionParser.parse(argv, strict: ["db-username": :string, "db-password": :string])
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.我到了Unknown option
.
有人知道是否有可能以某种方式?
typescript ×2
arguments ×1
c ×1
c++ ×1
clang ×1
elixir ×1
haskell ×1
llvm ×1
overloading ×1
polymorphism ×1
typeclass ×1
types ×1