typescript 相关问题

TypeScript是由Microsoft创建的JavaScript的类型超集,它添加了可选类型,类,接口,async / await和许多其他功能,并编译为纯JavaScript。此标记用于特定于TypeScript的问题。它不用于一般的JavaScript问题。

打字稿中 *.d.ts 与 *.ts 有什么区别?

我开始使用 TypeScript,我发现它真的很棒。但我对 *.d.ts 和 *.ts 之间的区别感到困惑。他们之间有什么区别?谁能用正确的方式解释我

回答 3 投票 0

同一页面上的组件更新作为 v-model 传递的错误数组

我有一个 Dropzone 组件,它将文件数组作为模型,并在提交文件时将文件附加到数组中。如果在页面中使用一次,效果很好,但如果有两个 Dropzone 组合...

回答 1 投票 0

自定义 vscode 扩展中的 Intellisense 不起作用

我已从 microsoft lsp-sample 复制了设置。Completion 的处理位于服务器中。 连接.onCompletion( (_textDocumentPosition:TextDocumentPositionParams):完成我...

回答 1 投票 0

Vue.js:同一页面上的组件更新作为 v-model 传递的错误数组

我有一个 Dropzone 组件,它将文件数组作为模型,并在提交文件时将文件附加到数组中。如果在页面中使用一次它效果很好,但如果有两个 Dropzone 组件...

回答 1 投票 0

如何使用 TypeScript 限制 JavaScript 值允许的操作集?

我有一些 JavaScript 对象,它们提供许多操作,其中一些操作无效,具体取决于对象的运行时(但恒定)状态。我希望使用 TypeScript 来限制

回答 1 投票 0

Material Tailwind - TypeError:无法读取 null 的属性(读取“useContext”)

我正在使用 React 和 Typescript 并使用 Material Tailwind UI - MT 制作一个客户端项目。但是当使用MT的组件时,我收到useContext错误,它似乎是在MT的theme.js中报告的。我...

回答 1 投票 0

如何在 Next.js 应用程序中使用类型安全从 Hono API 端点获取数据?

我目前正在将 Hono 与 Bun 结合用于我的 API 端点。现在,我正在使用 Next.js 构建一个单独的应用程序,我的目标是从 API 获取数据,同时确保类型安全。我的理解...

回答 1 投票 0

如何在Typescript中正确使用useField(Formik)?

当我尝试从我的传递所有道具(类型、占位符、类名等)时出现错误,我该如何修复它? ** 这是我的代码:** 当我尝试从我的<MyTextInput />传递所有道具(类型、占位符、类名等)时出现错误,我该如何修复它? ** 这是我的代码:** <MyTextInput label="Password:" name="password" placeholder="Enter your password" className="text-pink-600" /> 这是我的自定义输入组件: import { FieldHookConfig, useField } from 'formik'; import React from 'react'; interface IFieldProps { label?: string; } const MyTextInput: React.FC<IFieldProps & FieldHookConfig<string>> = ({ label, ...props }) => { const { name } = props; const [field, meta] = useField(props); // console.log({ field, meta, others }); return ( <div className="flex flex-col"> <label htmlFor={name}>{label}</label> <input id={name} type="text" {...field} {...props} /> // error here... </div> ); }; export default MyTextInput; ** 这是错误:** Type '{ ref?: LegacyRef<HTMLInputElement> | undefined; key?: Key | null | undefined; accept?: string | undefined; alt?: string | undefined; autoComplete?: HTMLInputAutoCompleteAttribute | undefined; ... 295 more ...; innerRef?: ((instance: any) => void) | undefined; } | { ...; } | { ...; }' is not assignable to type 'DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>'. Type '{ ref?: LegacyRef<HTMLSelectElement> | undefined; key?: Key | null | undefined; autoComplete?: string | undefined; disabled?: boolean | undefined; ... 275 more ...; checked?: boolean | undefined; }' is not assignable to type 'DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>'. Type '{ ref?: LegacyRef<HTMLSelectElement> | undefined; key?: Key | null | undefined; autoComplete?: string | undefined; disabled?: boolean | undefined; ... 275 more ...; checked?: boolean | undefined; }' is not assignable to type 'ClassAttributes<HTMLInputElement>'. Types of property 'ref' are incompatible. Type 'LegacyRef<HTMLSelectElement> | undefined' is not assignable to type 'LegacyRef<HTMLInputElement> | undefined'. Type '(instance: HTMLSelectElement | null) => void' is not assignable to type 'LegacyRef<HTMLInputElement> | undefined'. Type '(instance: HTMLSelectElement | null) => void' is not assignable to type '(instance: HTMLInputElement | null) => void'. Types of parameters 'instance' and 'instance' are incompatible. Type 'HTMLInputElement | null' is not assignable to type 'HTMLSelectElement | null'. Type 'HTMLInputElement' is missing the following properties from type 'HTMLSelectElement': length, options, selectedIndex, selectedOptions, and 4 more.ts(2322) (property) JSX.IntrinsicElements.input: React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> 我不想这样做:<input {...field} placeholder={props.placeholder} type={props.type} /> 我认为问题源于FieldHookConfig的定义: export type FieldHookConfig<T> = GenericFieldHTMLAttributes & FieldConfig<T>; 其中 GenericFieldHTMLAttributes 定义为 export type GenericFieldHTMLAttributes = | JSX.IntrinsicElements['input'] | JSX.IntrinsicElements['select'] | JSX.IntrinsicElements['textarea']; 基本上,TypeScript 会警告您,由于您使用的是 FieldHookConfig,因此您收到的属性总是有可能是 select 或 textarea 属性,这些属性与 input 不兼容。 我认为解决这个问题的最好方法是: import { FieldConfig, useField } from 'formik'; import React from 'react'; interface IFieldProps { label?: string; } const MyTextInput: React.FC<IFieldProps & FieldConfig<string> & JSX.IntrinsicElements['input']> = ({ label, ...props }) => { const { name } = props; const [field, meta] = useField(props); // console.log({ field, meta, others }); return ( <div className="flex flex-col"> <label htmlFor={name}>{label}</label> <input id={name} type="text" {...field} {...props} /> </div> ); }; export default MyTextInput; this should 将类型缩小为仅访问 input 属性。

回答 1 投票 0

Firebase 云功能以超时结束,而不是状态正常

我刚刚在我的应用程序中实现了支付网关。来自网关的最终交易状态在我的redirect_url 处收到,我已将其设置为我的 Google Firebase HTTPS Cloud 之一

回答 1 投票 0

向联合类型添加 prop 会弄乱联合

我想让我自己的输入元素表现得像React中的默认,允许它受控(使用值)或不受控(使用defaultValue)。 我在 TypeSc 中实现了这个...

回答 1 投票 0

NATS Jetstream 消费者并发

我的打字稿应用程序由多个项目组成,这些项目都有不同类型的微服务; server :将消息发布到 NATS 以便其他服务更新 (mongo) DB 的 REST API

回答 1 投票 0

如何强制执行 TypeScript 类型,其中只有一个字段是字符串,所有其他字段都是数字?

我正在使用 TypeScript,需要为一个对象定义一种类型,其中所有字段都限制为数字,除了一个名为 order 的特定字段(它应该是字符串)。我怎样才能

回答 1 投票 0

如何在 TypeScript 中将特定字符串类型转换为小写?

我必须更改定义为“GET”的特定字符串 | '发布'| '补丁' | “DELETE”为小写,不会丢失有关类型的信息。当我只执行 method.toLowerCase() 时,它会更改其类型......

回答 1 投票 0

Electron Js - 自定义菜单栏

我正在使用 Electron 构建桌面应用程序(到目前为止仅支持 Mac)。 我希望能够使用 Electron 菜单,但我不知道是否可以使用一些 HTML 和 JS 来...

回答 1 投票 0

Ngx-Mask 将输入转换为十进制数

如何使用 ngx-mask 将输入转换为十进制数字,以便用户看到它,例如,123 变为 123.00,142.1 变为 142.10,73.30 仍为 73.00? 我已经尝试过

回答 1 投票 0

当有一个名为“valueOf”的道具时可能出现打字稿问题?

这会产生预期的错误: 输入保罗 = { 道具:字符串, 其他值:字符串, } 类型 Treta = 记录 对象> const ugulha : Treta = { //错误:属性 '

回答 1 投票 0

ChartJS:分组堆叠条形图渲染不正确

我正在尝试使用 ChartJS 创建分组堆积条形图。在我的数据集中,有 2 个组:A 组和 B 组。A 组渲染正确,但由于某种原因,B 组(灰色...

回答 1 投票 0

RTK端点之间的查询缓存

我无法理解 RTK 查询的缓存行为。 从 'react' 导入 React, { useState }; 从'react-dom/client'导入{createRoot}; 从'react-redux'导入{Provider};

回答 1 投票 0

如何使 Angular 组件更通用以接受多种数据类型作为@Input?

我有一个组件,可以从后端获取数据,将其显示在表格中并允许用户进行选择。 整个组件基于获取数据的类型,因此它受到强烈的限制

回答 1 投票 0

KeyCloak-js 和 vue3 - 需要一些页面公开

我正在将 keycloak-js 适配器与 Vue 3 应用程序一起使用。这个系统有一些公共页面,所以我不能立即调用keycloak。我已经设置了一个按钮来调用登录页面,但令牌不是...

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.