小编Ant*_*man的帖子

使用 SvelteKit 从“$lib”导入时找不到模块 [...] 或其相应的类型声明 (js2307)

使用最新的 SvelteKit (1.0.0-next.401) 我在使用语法从 lib 导入组件时遇到问题$lib。我收到错误和红色波浪线(即使导入和网络应用程序工作正常)。

在此输入图像描述

错误信息如下:

找不到模块“$lib/components/shared/header.svelte”或其相应的类型声明。js(2307)

如果使用相对路径,错误就会消失。

typescript eslint svelte sveltekit

10
推荐指数
3
解决办法
2万
查看次数

如何在 ASP.NET Core 中构建之前运行特定的 NPM 命令?

我正在尝试在我的 ASP.NET Core 应用程序中为 Angular 运行特定的 NPM 命令。NPM 没什么特别的,它只是准备了一些文件。

如何在每次构建 ASP.NET Core 之前自动运行 NPM 脚本?

Angular 应用程序位于 ClientApp 文件夹中,其中包含 package.json。

asp.net npm single-page-application asp.net-core angular

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

Vue 3 和 Typescript - 无法访问方法中的数据属性

我试图以我正在编写的方法访问我的数据,但它似乎不起作用。我收到 TS2339 Typescript 错误,指出该类型中不存在该属性。

TS2339: Property 'players' does not exist on type '{ onAddPlayers(): void; getPlayerPlaceholder(index: number): string; }'.   
    47 |   methods: {
    48 |     onAddPlayers() {
  > 49 |       this.games = prepareGames(this.players as PadelPlayer[]);
       |                                      ^^^^^^^
    50 |     },
    51 |     getPlayerPlaceholder(index: number) {
    52 |       const playerNumber = Number(index) + 1;
Run Code Online (Sandbox Code Playgroud)

这是组件的代码:

<script lang="ts">
import { PadelGame } from "@/models/padelGame.interface";
import { getPadelPlayers, prepareGames } from "../services/americanoService";
import { PadelPlayer } from "@/models/padelPlayer.interface";

const padelGames: PadelGame[] = []; …
Run Code Online (Sandbox Code Playgroud)

javascript typescript vue.js vue-component vuejs3

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

在函数外使用变量

我已经定义了一个函数,它将从用户输入中获取一个值。这是一个路径(基于 appJar 的 .directoryBox)。我已将目录框的代码放在一个函数中弹出,以便在按下按钮时显示。但是,我似乎无法在函数之外使用该值。

代码的重要部分如下所示:

def dirfunction(button):
    dirr = app.directoryBox('box')
    app.setEntry('Directory', dirr)
    app.showButton('Search')
    return dirr

def searchfunction(button):
    if button == 'Search':
        findBigfile.findBigFiles(dirr, mbSize)


mbSize = app.addLabelEntry('Size in MB')
app.addLabelEntry('Directory')
app.setLabelWidth('Size in MB', '10')
app.setLabelWidth('Directory', '10')

app.addButton('Choose Directory', dirfunction)
app.addButton('Search', searchfunction)
app.hideButton('Search')

app.go()
Run Code Online (Sandbox Code Playgroud)

我尝试在 dirfunction 之外使用 'dirr' 变量,但我无法让它工作。它只在内部有效。

编辑:我也不能在函数之外创建 app.directoryBox,因为这会导致在打开应用程序时直接出现弹出窗口。

python python-3.x

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

为什么大熊猫不创建一个excel文件?

我正在尝试为我生成的数据库创建一个带有 Pandas 的 excel 文件。

我都试过:

import pandas as pd

# write database to excel
df = pd.DataFrame(database)

# Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pd.ExcelWriter('fifa19.xlsx', engine='xlsxwriter')

# Convert the dataframe to an XlsxWriter Excel object.
df.to_excel(writer, sheet_name='Sheet1')

# Close the Pandas Excel writer and output the Excel file.
writer.save()
Run Code Online (Sandbox Code Playgroud)

也:

import pandas as pd
df = pd.DataFrame(database).T 
df.to_excel('database.xls')
Run Code Online (Sandbox Code Playgroud)

但是,这些选项都不会生成 Excel 文件。数据库是一本字典。

python excel pandas

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

xunit 中的异常消息包含参数,因此我的测试失败

我试图检查我抛出的异常是否给出了正确的错误消息。

我在类中有一个方法可以从值中提取(减去)。如果该值小于 0,我会抛出异常。

if (amount < 0)
{
    throw new System.ArgumentOutOfRangeException("amount", AmountLessThanZeroMessage);
}
Run Code Online (Sandbox Code Playgroud)

这是我的错误消息:

public const string AmountLessThanZeroMessage = "Amount is less than zero";
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试编写单元测试以查看是否收到正确的消息时,它因参数而失败。这是测试:

[Fact]
public void CannotWithdrawLessThanZero()
{
    // Arrange
    var account = new Account("User", 23);

    // Act
    account.DepositCash(100);
    var thrownException = Assert.Throws<ArgumentOutOfRangeException>(() => account.WithdrawCash(-10));

    // Assert
    Assert.Equal(Account.AmountLessThanZeroMessage, thrownException.Message);
}
Run Code Online (Sandbox Code Playgroud)

结果最后包含参数,导致测试失败: 在此输入图像描述

看起来实际的消息包括它引用的参数。我该如何更正此消息?我应该将该行添加(Parameter 'amount')到预期的字符串中,还是有更好的选择?

c# unit-testing exception xunit

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