在 Haskell 中,我们可以声明允许我们隐藏对底层数据类型的访问的新类型。这允许我们通过不暴露底层数组之类的东西(使库的用户不可能越界)来在模块中创建更安全的 API。
打字稿中是否有类似于 newtypes 的东西?
我使用Firebase云功能为QR文件上传编写了以下代码
const functions = require('firebase-functions');
const qrcode = require('qrcode')
const admin = require('firebase-admin');
const spawn = require('child-process-promise').spawn;
const serviceAccount = require("./secret.json");
const gcs = require('@google-cloud/storage')();
admin.initializeApp(functions.config({
credential: admin.credential.cert(serviceAccount),
storageBucket: "https://SECRET.firebaseio.com"
}));
exports.qrcode = functions.https.onRequest((req, res) => {
const storage = admin.storage().bucket();
const dummyFile = storage.file('dummy.png')
new Promise ((resolve, reject) => qrcode.toFileStream(
dummyFile.createWriteStream()
.on('finish', resolve)
.on('error', reject),
'DummyQR'))
.then(console.log("success")) //Doing stuff here later
.catch(console.log)
res.send("<script>window.close();</script>")
});
Run Code Online (Sandbox Code Playgroud)
根据文档,我应该能够通过简单地调用admin.storage().bucket();
(https://firebase.google.com/docs/storage/admin/start)连接到存储桶,但是出现以下错误:
Error: Error occurred while parsing your function triggers.
Error: Bucket …
Run Code Online (Sandbox Code Playgroud) google-cloud-storage firebase google-cloud-functions firebase-admin
我正在尝试将精力放在基于属性的测试和国际象棋上。目前,我将我的国际象棋游戏表示为2D数组,而我实现的唯一部件是用来作怪的典当和骑士。
典当和骑士代表他们的动作allMoves(x,y) \ invalidMoves(board,x,y)
。因此,我可以想到的一项性能就是对其进行测试allMoves(x,y) ? invalidMoves(board,x,y) === allMoves
。但是除此之外,我不确定还需要测试什么。我假设我需要为国际象棋棋盘建立一个简化的Oracle模型,但是我不确定这样的模型是什么。
I want to check if a type is nullable or not, and if it has a conditional type on the value.
I tried implementing
type IsNullable<T> = T extends null ? true : false;
Run Code Online (Sandbox Code Playgroud)
However, it does not seem to work
type test = IsNullable<number> // Returns false as it should
type test = IsNullable<number | null> // Returns false when it should be true
Run Code Online (Sandbox Code Playgroud)
What's the proper way of checking if a type is nullable? I tried with T …
我正在尝试在 Terraform 中设置 S3 存储桶策略。我在模块中编写了以下代码core/main.tf
:
resource "aws_s3_bucket_policy" "access_to_bucket" {\n\n bucket = aws_s3_bucket.some_bucket.id\n\n policy = jsonencode({\n Version = "2012-10-17"\n Statement = [\n {\n Action = ["s3:GetObject", "s3:GetObjectAcl", "s3:ListBucket"]\n Effect = "Allow"\n Principal = "${var.some_variable_name}"\n Resource = [\n "${aws_s3_bucket.some_bucket.arn}",\n "${aws_s3_bucket.some_bucket.arn}/*"\n ]\n },\n ]\n })\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n然后在本地模块中实例化,该模块使用 localstack 在本地运行。
\n这是生成的计划:
\nTerraform will perform the following actions:\n\n # module.local.aws_s3_bucket_policy.access_to_bucket will be created\n + resource "aws_s3_bucket_policy" "access_to_bucket" {\n + bucket = "some_bucket"\n + id = (known after apply)\n + policy …
Run Code Online (Sandbox Code Playgroud) amazon-s3 amazon-web-services terraform terraform-provider-aws