我正在使用nodeJS v12.10.0 这支持Intl.ListFormat
使用Typescript v3.6.3
但是,当使用打字稿进行编译时,出现Property 'ListFormat' does not exit on type 'typeof Intl' (ts2339)错误。
我尝试过谷歌搜索并找到了这个和其他建议,但没有任何效果。
我发现的共识似乎是使用文件name.d.ts
并以某种方式扩展Intl
那里的对象,但我无法做到。
我仍在学习 typescript,但熟悉 javascript。
在 Jest 中测试函数后,我需要关闭 PG-Promise 数据库连接。
这是在一个地方(db.js)和require
d 在任何需要它的地方初始化。在下面的代码的情况下,seed.js需要它,seed.spec.js正在测试它。
我知道afterAll
Jest 中有一个钩子,但这会在任何地方关闭连接,这可能会导致测试错误地失败?
该问题已通过该--forceExit
选项解决,但它给出了一条错误消息,并且感觉不是解决此问题的正确方法?
数据库.js:
const pgp = require('pg-promise')();
const db = pgp(connection);
module.exports = {db, pgp};
Run Code Online (Sandbox Code Playgroud)
种子.spec.js:
require('dotenv').config();
const {pgp} = require('./db');
expect.extend(require('jest-json-schema').matchers);
const schema = require('./schemas');
const generate = require('./generate');
const seed = require('./seed');
const data = generate();
test ('the data returned by the seed function matches the schema', () => {
return seed(data)
.then(outputData => {
expect(outputData).toMatch(schema); …
Run Code Online (Sandbox Code Playgroud) 我怎样才能使<legend>
跨越所有行,这样它就会弄乱样式<fieldset>
为 3 列的 CSS 网格?
<fieldset>
<legend>Personal Details</legend>
<label class="field__label" for="first-names">
First names
</label>
<input class="form__entry" id="first-names" type="text" name="firstName">
<span class="form__feedback form__instructions">
Must only use letters, spaces, hyphens and apostrophes
</span>
</fieldset>
Run Code Online (Sandbox Code Playgroud)
CSS:
form {
display: grid;
grid-template-columns: minmax(100px, max-content) minmax(200px, max-content) minmax(200px,1fr);
grid-gap: 10px;
}
fieldset {
display: contents;
}
Run Code Online (Sandbox Code Playgroud) 这个函数找到了第n个斐波那契的作品.
a = 1
b = 2
fibonacci :: Int -> Int
fibonacci 1 = a
fibonacci 2 = b
fibonacci n = (fibonacci (n-1)) + (fibonacci (n-2))
Run Code Online (Sandbox Code Playgroud)
但它很慢.如果我这样做map fibonacci [1..]
,真的会随着数字的增加而减慢.我猜这是开销,因为正在使用多少堆栈和大量的计算 - 将每一个计算到底a
,b
而不是仅仅将最后两个放在一起.
我怎样才能改进它以便它更快,但仍然使用函数式编程风格?(我是一个明确的haskell和FP新手!)我在Python中尝试了一些比较闪电的东西.
如果不是比工作代码更受欢迎,提示也是受欢迎的!
javascript ×2
node.js ×2
css ×1
css-grid ×1
fibonacci ×1
haskell ×1
html ×1
jestjs ×1
pg-promise ×1
postgresql ×1
typescript ×1