使用最新的 SvelteKit (1.0.0-next.401) 我在使用语法从 lib 导入组件时遇到问题$lib。我收到错误和红色波浪线(即使导入和网络应用程序工作正常)。
错误信息如下:
找不到模块“$lib/components/shared/header.svelte”或其相应的类型声明。js(2307)
如果使用相对路径,错误就会消失。
我正在尝试在我的 ASP.NET Core 应用程序中为 Angular 运行特定的 NPM 命令。NPM 没什么特别的,它只是准备了一些文件。
如何在每次构建 ASP.NET Core 之前自动运行 NPM 脚本?
Angular 应用程序位于 ClientApp 文件夹中,其中包含 package.json。
我试图以我正在编写的方法访问我的数据,但它似乎不起作用。我收到 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) 我已经定义了一个函数,它将从用户输入中获取一个值。这是一个路径(基于 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,因为这会导致在打开应用程序时直接出现弹出窗口。
我正在尝试为我生成的数据库创建一个带有 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 文件。数据库是一本字典。
我试图检查我抛出的异常是否给出了正确的错误消息。
我在类中有一个方法可以从值中提取(减去)。如果该值小于 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')到预期的字符串中,还是有更好的选择?
python ×2
typescript ×2
angular ×1
asp.net ×1
asp.net-core ×1
c# ×1
eslint ×1
excel ×1
exception ×1
javascript ×1
npm ×1
pandas ×1
python-3.x ×1
svelte ×1
sveltekit ×1
unit-testing ×1
vue.js ×1
vuejs3 ×1
xunit ×1