小编Emi*_*zer的帖子

如何在 TypeScript 中内联导入另一个源

在 node.js Javascript 中,我可以这样做:

class MyClass{
    data(){
        return [
            require('this-module'),
            require('another-module),
            require('that-module),
        ];
    }
}
Run Code Online (Sandbox Code Playgroud)

在打字稿中,我可以写:

import * as ThisModule from 'this-module'
import * as AnotherModule from 'another-module'
import * as ThatModule from 'that-module'

class MyClass{
    data():MyModuleTypeArray{
        return [
            ThisModule,
            AnotherModule,
            ThatModule
        ];
    }
}
Run Code Online (Sandbox Code Playgroud)

但在那个解决方案中,我必须将每个名字写 3 次。

我的问题:我可以在 Typescript 中编写代码以进行内联包含或以其他不需要编写 3 倍名称(或使用辅助变量)的方式编写代码吗?

当然我可以写requirerequire返回any。我想要类型检查。

typescript

5
推荐指数
1
解决办法
2876
查看次数

zig 中 `std.io.getStdOut().writer();` 的类型是什么?

我无法使用 zig 中的标准输出初始化全局变量:

var out = std.io.getStdOut().writer();
Run Code Online (Sandbox Code Playgroud)

然后我尝试在 中初始化fn main并将全局变量声明为可选(由 null 初始化)。

我的问题是我不知道哪种类型std.io.getStdOut().writer();

我尝试过类似的东西:

var out: std.fs.Writer? = null
//...
fn main() !void {
   out = std.io.getStdOut().writer();
   //...
   out.print("ok: {}", "ok");
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过反思:

var stdout: @typeInfo(@TypeOf(std.io.getStdOut().writer())).Fn.return_type.? = null;
Run Code Online (Sandbox Code Playgroud)

我需要知道如何声明一个变量或一个返回 Writer 的函数(即内部具有常用打印函数的东西)。

已编辑

使用 zig 版本 0.12.0-dev.1150+3c22cecee 和 0.11.0 并列两次

writer.zig 文件包含:

const std = @import("std");

var out = std.io.getStdOut().writer();

pub fn main() anyerror!void {
    try out.print("{any}\n", .{@TypeOf(out)});
}
Run Code Online (Sandbox Code Playgroud)

我收到错误:无法评估 comptime 表达式

zig build-exe writer.zig && …
Run Code Online (Sandbox Code Playgroud)

writer zig

5
推荐指数
1
解决办法
194
查看次数

错误:打字稿任务检测未为以下配置贡献任务

我尝试在task.json中放置一个用于打字稿类型task的路径:

{
    "version": "2.0.0",
    "tasks": [
        {   
            "identifier": "tsc-client", 
            "label": "tsc-client", 
            "type": "typescript",
            "tsconfig": "src/client/tsconfig.json",
            "problemMatcher": [
                "$tsc"
            ]
        },
        {   
            "identifier": "tsc-server", 
            "label": "tsc-server", 
            "type": "typescript",
            "tsconfig": "src/server/tsconfig.json",
            "problemMatcher": [
                "$tsc"
            ]
        },
        {
            "identifier": "build-all",
            "label": "build-all",
            "dependsOn": ["tsc-client", "tsc-server"]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

然后在我的launch.json中,我有:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "preLaunchTask": "tsc-client",
            "name": "Launch Program",
            "program": "${workspaceFolder}/server/server-repsic.js"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我大声说,我得到:

Error: The typescript task detection didn't contribute a task for the following configuration: …
Run Code Online (Sandbox Code Playgroud)

typescript tsc visual-studio-code vscode-tasks

2
推荐指数
2
解决办法
2610
查看次数

如何在木偶戏中隐藏地址栏(无头假)

我想用无头虚假启动Chromium并隐藏地址栏(以及菜单,工具等其他内容)

const puppeteer = require('puppeteer');

(async () => {
    console.log('launching');
    const browser = await puppeteer.launch({headless: false});
    const page = await browser.newPage();
    await page.goto('https://stackoverflow.com');
    await page.setViewport({width:400, height:300});
    await page.keyboard.press('F11'); //doesn't work and it is'n exact I want
})();
Run Code Online (Sandbox Code Playgroud)

我明白了:

我明白了

我想要:

在此输入图像描述

puppeteer

1
推荐指数
1
解决办法
1085
查看次数