AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-403425

Kevin Renskers's questions

Martin Hope
Kevin Renskers
Asked: 2024-11-20 20:07:29 +0800 CST

Svelte 5 动态组件加载:TypeScript 错误

  • 6

在我的 Svelte 4 应用中,我动态加载了组件,所有组件都有不同的 props。非常简单的复制(也可在Svelte Playground上使用):

// App.svelte
<script lang="ts">
  import One from "./One.svelte";
  import Two from "./Two.svelte";

  import type { ComponentType } from "svelte";

  type Item = {
    component: ComponentType;
  };

  const items: Item[] = [
    { component: One, one: "World" },
    { component: Two, two: "Svelte" },
  ];
</script>

<div class="container py-20 text-white">
  {#each items as item}
    <div>
      <svelte:component this={item.component} {...item} />
    </div>
  {/each}
</div>
// One.svelte
<script lang="ts">
    export let one;
</script>

Hello {one}
// Two.svelte
<script lang="ts">
    export let two;
</script>

Goodbye {two}

运行良好,没有任何警告或错误,到目前为止没有任何投诉。但是我想迁移到 Svelte 5,现在我收到一堆 TypeScript 错误。例如ComponentType已弃用,以及类似以下内容:

Type '__sveltets_2_IsomorphicComponent<{ one: any; }, { [evt: string]: CustomEvent<any>; }, {}, {}, string>' is not assignable to type 'ComponentType'.
  Type '__sveltets_2_IsomorphicComponent<{ one: any; }, { [evt: string]: CustomEvent<any>; }, {}, {}, string>' is not assignable to type 'new (options: ComponentConstructorOptions<Record<string, any>>) => SvelteComponent<Record<string, any>, any, any>'.
    Types of parameters 'options' and 'options' are incompatible.
      Type 'ComponentConstructorOptions<Record<string, any>>' is not assignable to type 'ComponentConstructorOptions<{ one: any; }>'.
        Property 'one' is missing in type 'Record<string, any>' but required in type '{ one: any; }'.

我该如何重构代码,使其继续工作,而不会出现 TypeScript 错误,并且不必对每个组件进行强类型化?在我的实际应用中,涉及许多组件,每个组件都有一大堆不同的 props。我不想为每个组件创建类型别名。

只需更改ComponentType为Component即可消除弃用警告,但其他警告基本仍然相同:

Type '__sveltets_2_IsomorphicComponent<{ one: any; }, { [evt: string]: CustomEvent<any>; }, {}, {}, string>' is not assignable to type 'Component<{}, {}, string>'.
  Types of parameters 'props' and 'props' are incompatible.
    Type '{}' is not assignable to type '{ one: any; } & { $$events?: { [evt: string]: CustomEvent<any>; } | undefined; $$slots?: {} | undefined; }'.
      Property 'one' is missing in type '{}' but required in type '{ one: any; }'.ts(2322)

更改ComponentType为SvelteComponent也不会让事情变得更好。当我使用该unknown类型时,我收到此警告:

Argument of type 'unknown' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent | Component<any, any, any> | null | undefined'.

至少那只是一个警告,而不是数组中的一大堆,所以更好,但这真的不能用更好的方法解决吗(无需输入每个组件)?

svelte
  • 1 个回答
  • 31 Views
Martin Hope
Kevin Renskers
Asked: 2024-10-25 21:22:37 +0800 CST

是否总是从主位置启动我的 Fish shell,而不是从之前的位置启动?

  • 5

我使用 Fish shell,使用来自此点文件存储库的配置:https://github.com/kevinrenskers/dotfiles/tree/main/fish。

问题是,每当我在终端中打开新选项卡时,它都会从上一个路径开始,而不是从我的用户主文件夹开始。如何更改此行为,以便每个终端始终从打开~?

奇怪的是,我一直在使用这些点文件,从来没有遇到过这个问题,直到我格式化我的电脑并从头开始设置。不知道为什么现在它会这样,但我真的不喜欢它。

fish
  • 1 个回答
  • 18 Views
Martin Hope
Kevin Renskers
Asked: 2024-07-15 23:25:55 +0800 CST

SvelteKit 在“load”函数内部执行请求时不存储 cookie

  • 6

LayoutServerLoad在我的 SvelteKit 网站中,我在函数内部向后端发出请求+layout.server.ts。即当使用查询参数打开网站时?affiliate_id=bla,我想将其发送到后端:

import type { LayoutServerLoad } from "./$types";
import { keyBy } from "$lib/utils";
import { backendUrl } from "$lib/config";

export const trailingSlash = "always";

export const load: LayoutServerLoad = async ({ locals, url, fetch }) => {
  const affiliate_id = url.searchParams.get("affiliate_id");
  if (affiliate_id) {
    const headers = {
      "Content-Type": "application/json",
      "X-CSRFToken": locals.csrfToken,
    };

    fetch(`${backendUrl}/shop/basket/`, { method: "POST", credentials: "include", headers, body: JSON.stringify({ affiliate_id }) })
      .catch(error => {
        console.error("Error storing affiliate_id: ", error);
      });
  }

  return {
    // I'm returning a bunch of data here
  };
};

问题是后端响应包含set-cookie标头,并且 cookie 没有存储在浏览器中。

当我将load函数更改为仅返回affiliate_id:

export const load: LayoutServerLoad = async ({ locals, url }) => {
  return {
    affiliateId: url.searchParams.get("affiliate_id"),
    // and more data
  };
};

然后在里面发出请求+layout.svelte,那么一切就正常工作了。

<script lang="ts">
  import type { PageData } from "./$types";
  import { onMount } from "svelte";

  export let data: PageData;
  const { affiliateId } = data;

  onMount(async () => {
    if (affiliateId) {
      // Do the request here
    }
  });
</script>

<slot />

现在,响应中的 cookie 已正常存储在浏览器中。

为什么在函数中做同样的请求时,cookie没有被存储呢load?

sveltekit
  • 1 个回答
  • 17 Views
Martin Hope
Kevin Renskers
Asked: 2023-09-11 20:53:12 +0800 CST

Django Admin:在一个部分中同时显示多个应用程序?

  • 6

我正在为一家网上商店开发 Django API,并将模型和视图组织到不同的应用程序中:一个用于订单,一个用于购物篮,一个用于产品,一个用于报价。现在我想将这些模型添加到管理站点,但我不希望它显示为四个不同的部分,每个部分都有一个模型需要管理。相反,我想要一个新的“商店”部分,在其中显示所有这些应用程序的模型。

所以代替这个:

在此输入图像描述

我希望这两种模型都位于一个公共部分。这可能吗?

我尝试在两个应用程序的文件中设置相同的详细名称apps.py,但这只会导致两个具有相同名称的部分:

在此输入图像描述

django
  • 2 个回答
  • 24 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve