我对JavaScript中的宏很好奇,并对babel-plugin-macros和Sweet.js彼此之间的比较感到困惑。他们都解决相同的问题吗?它们都适合同一工具链吗?
特别是,我希望将这些工具之一与ES2015代码一起使用,这些代码将使用Webpack和Babel转换为ES5,并且不确定这些工具中的任何一个如何与转换进行交互。
该角2个文档说,像这样定义一个组件,使用魔法字符串选择名称:
import { Component } from '@angular/core';
@Component({
selector: 'card',
template: `
<div class="card">{{title}}</card>
`
})
export class Card {
title = 'Card Title';
}
Run Code Online (Sandbox Code Playgroud)
如果我这样做,我是否坚持<card>将来作为使用此组件的唯一方法?应用程序是否只有一种带有此选择器的组件?例如,是否可以使用<card>第三方库,并使用我自己的<card>?
这在React中是微不足道的,因为组件名称只是变量.
import OtherCard from 'card'
const Card = title => <div className="card">{title}</div>
const Composable = title => <OtherCard><Card title={title} /></OtherCard>
Run Code Online (Sandbox Code Playgroud)
我问的原因之一是我可以知道是否在Angular 1和Objective-C中命名Angular 2组件选择器:
selector: 'initech-card'
Chrome不会为HTML内联包含的脚本加载源地图。
<script type="text/javascript">!function t(n,e,r){ /* more code */}()
//# sourceMappingURL=public/js/edit-before.js.map
</script></body>
Run Code Online (Sandbox Code Playgroud)
我知道Chrome不会请求源地图,因为我将服务器设置为记录所有请求,并且还检查了Chrome网络控制台。我验证了源映射的路径是正确的,浏览器没有找到它。
Chrome是否应在script代码中加载JS的源映射?如果是这样,我在做什么错?
我在模式匹配中对此进行了调查
| {call_name = #bundle_source; _ }
在代码的早期,bundle_source定义为type(type bundle_source = ...).
那么哈希标志是什么意思呢?{call_name = #bundle_source }在模式匹配中是否意味着call_name预期值具有类型bundle_source?
我搜索了手册中的"哈希标志"和"英镑标志",但一无所获.
Why am I getting this error (on the last line)?
declare function f0<A, B>(a: A, b: B): string
declare function f0<A>(a: A): boolean;
declare function wrap
<Ret, A>(f: (a: A) => Ret): (a: A) => Ret[]
declare function wrap
<Ret, A, B>(f: (a: A, b: B) => Ret): (a: A, b: B) => Ret[]
const f1 = wrap(f0)
const b1: boolean[] = f1(1)
const s1: string[] = f1(1, 2) // Error: expected 1 arguments but got 2
Run Code Online (Sandbox Code Playgroud)
It seems the …
在Pijul中我怎样才能看到补丁中发生了什么?我正在寻找类似的东西git diff <commit> <commit>^。
我尝试过pijul diff,但它似乎只适用于分支机构。我也无法pijul log显示补丁的任何细节。
我怀疑我正在寻找的东西是可能的,因为单击Nest中的补丁会显示差异,并且 libpijul 中有补丁漂亮打印,其中包括更改列表。
我希望定义一个type可以只有一个键的对象。
这是一个尝试:
type OneKey<K extends string> = Record<K, any>
Run Code Online (Sandbox Code Playgroud)
不幸的是,这并不完全有效,因为变量可以具有联合类型:
type OneKey<K extends string> = Record<K, any>
declare function create<
K extends string,
T extends OneKey<K>[K]
>(s: K): OneKey<K>
const a = "a";
const res = create(a);
// Good
const check: typeof res = { a: 1, b: 2 }
// ~~ Error, object may only specify known properties
declare const many: "a" | "b";
const res2 = create(many);
// **Bad**: I only want one key
const check2: …Run Code Online (Sandbox Code Playgroud) 我希望添加规范永远不会降低安全性,但这正是以下情况发生的情况。
在下面的代码中,Dialyzer(错误地)相信我 bar 的返回类型是1. 这导致它说 foo() 中的模式永远不能匹配 - 如果注意不正确的建议,将引入运行时错误!
-module(sample).
-export([foo/0]).
foo() ->
case bar() of
1 -> ok;
2 -> something
end.
-spec bar() -> 1.
bar() ->
rand:uniform(2).
Run Code Online (Sandbox Code Playgroud)
删除规范以bar/0解决问题——但为什么 Dialyzer 信任我?Dialyzer 在这里违反了它的“无误报”承诺:它在没有错误时发出警告。并且(甚至更糟)透析器轻推引入一个新的错误。
当类型参数受类型限制时,这意味着什么Fn?
fn call<F: Fn() -> u64>(f: F) -> u64 {
f()
}
Run Code Online (Sandbox Code Playgroud)
Rust Book 说带有类型参数的函数是单态的:https://doc.rust-lang.org/stable/book/ch10-01-syntax.html ?highlight=generic%20function#performance-of-code-using-仿制药。
如果是这种情况,那么我希望call为实例化的每个新闭包类型生成一个新版本。
根据 Rust 参考,即使函数体相同,每个闭包类型也是不同的: https: //doc.rust-lang.org/reference/types/closure.html。
call因此,当我查看该程序的编译输出时,我预计当我使用1799999999999999999不同的实例进行调用时,与仅四个实例相比,编译工件会更大F,但事实并非如此。
(1)
// `call` is defined above
fn make_closure(n: u64) -> impl Fn() -> u64 {
move || n
}
fn main() {
let results = (0..17999999999999999999).map(make_closure).map(call);
for r in results {
println!("{}", r)
}
}
Run Code Online (Sandbox Code Playgroud)
那么什么才是正确的心智模型fn call<F: Fn() -> u64> 呢?我是否应该将代码膨胀的缺乏视为仅仅是一种优化? …
在这里,我将加法编码为 1 作为包装元组类型,将减法编码为提取元组类型的第二个元素:
type zero = unit * unit
type 'a minus1 = 'snd constraint 'a = unit * 'snd
type 'a plus1 = unit * 'a
Run Code Online (Sandbox Code Playgroud)
到目前为止,编码有效:
type one = zero plus1
type two = one plus1
type two' = zero plus1 plus1
type two'' = unit * (unit * (unit * unit))
let minus1 ((), n) = n
let plus1 n = ((), n)
let zero = ((), ())
let one : one = plus1 zero
let two …Run Code Online (Sandbox Code Playgroud) ocaml ×2
types ×2
typescript ×2
angular ×1
babeljs ×1
browser ×1
components ×1
dialyzer ×1
erlang ×1
generics ×1
javascript ×1
pijul ×1
rust ×1
source-maps ×1
sweet.js ×1
union-types ×1
web ×1
webpack ×1