typescript相关内容
目标是定义只接受一定数量的强制参数的函数类型。 感谢@jcalz Whohelped me定义了类型OnlyTupleRequired,该类型允许删除任何可选参数,并且到目前为止允许知道参数的长度,即使它们包括可选参数,我也做到了。 现在,我希望编译器对函数的定义而不是对它们的使用提出警告--任何声明‘Share Error’的注释都应该发出错误,而不会发出错误。 这里是指向pl
..
我正在使用TypeScrip构建一个Next.js项目。我正在尝试键入基于Redux状态重定向用户的即席。 以下是我到目前为止的情况: import { RootState } from 'client/redux/root-reducer'; import Router from 'next/router.js'; import { curry } from 'ramda'; imp
..
按照惯例,开发人员将全局包含全局DOM类型并在全局使用它们。 { "compilerOptions": { "lib": [ "dom" ] }, } 是否可以显式使用DOM类型? 类似: import { MessagePort, HTMLElement } from 'dom' 推荐答案 您不能import来自lib.dom.
..
我正在看这本手册,我发现了一些非常令人困惑的东西,我不确定如何使用它。基本上是同时是函数和属性的参数。 // the definition type DescribableFunction = { description: string; (someArg: number): boolean; }; // the function that acceps the params fun
..
我终于成功地创建了一个泛型类型,它为我提供了json键列表/值的所有可能组合。我甚至准备了一个方法来限制递归。 type EditAction = { data : T[P] id : [...Prev, P] prev : Prev } type EditActions
..
在尝试用TypeScrip创建工厂时,我遇到了this article,我被这部分搞糊涂了: class UserFactory { static getUser(k: Keys) : ExtractInstanceType { return new userMap[k](); } 引用的类型定义: type ExtractInstance
..
对于我的项目,我需要提供一种打字类型,即所谓的CardSize。 此类型可以采取多种形式。它可以是静态值、响应值(特定于断点),也可以是由空格分隔的二者的组合。 可能的(单数)值如下: type CardSize = 'compact' | 'normal' | 'compact@small' | 'compact@medium' | 'compact@large' | 'nor
..
大家好,我正在寻找一种从联合打字类型获取数组的方法 这是现有类型: export type GridClassKey = | 'root' | 'container' | 'item' | 'zeroMinWidth' | 'direction-xs-column' | 'direction-xs-column-reverse' | 'direction-
..
我有一个PersonTypes对象数组,并且只想在forEach循环中使用Partial Of键。还有什么 打字稿中精确、正确的编码以提供一种类型?我可以做一些类似的事情 people.forEach((person: Pick 或 people.forEach((person: PersonTypes) =>{ 或 people.f
..
我有一个按键处理函数,定义如下: handleOnKeyDown = (e: React.KeyboardEvent) => { if (key.isEscape(e.key)) { stopEvent(e); this.props.handleClose(e); } } 但是,在我的代码的另一部分中,此
..
我从TypeScrip文档中看到,您不能从类型UNKNOWN访问属性: // No property accesses, element accesses, or function calls function f11(x: unknown) { x.foo; // Error x[5]; // Error x(); // Error new x();
..
如何键入一个函数来有效地执行lodash.sumby对键的操作?DefinitelyTyped types for it是松散的,不指定字符串参数需要是集合类型的键。 以下内容似乎很接近,但它没有指定T[key]的类型是数字 function sumByKey(list: T[], key: keyof T) { return list.reduce((sum, item)
..
我在ReactJS上使用useReducer,并且我已经定义了几个操作接口来在我的reducer function中使用它们。我看到我使用相同的属性,但有时使用不同的有效负载值。 interface MembersAction { type: "JOIN" | "LEAVE"; payload: string; } interface MessagesAction { type
..
我在一个打字项目中使用passport。The DefinitelyTyped type definition for passport重写Express请求以包括user属性。但它将用户定义为空界面: index.d.ts declare global { namespace Express { ... // tslint:disable-ne
..
我正在使用TypeScrip和Firebase,我有一个带有此函数的小抽象层,用于根据文档的字段名称和值搜索唯一的文档。 where(fieldName: K, operator: WhereFilterOp, value: unknown): Query { this.addCriterion(n
..
请看下面的打字稿片段。 为什么不抛出编译错误呢?这难道不是一个明显的打字错误吗?我必须更改什么才能使它再次成为类型安全的?TYVM type A
= { p?: never, q?: Partial
} type B
= { p?: Partial
q?: never } type C
= A
| B
const c: C
..
我正在尝试为没有类型的包提供类型: error TS7016: Could not find a declaration file for module 'inputmask-core'. './node_modules/inputmask-core/lib/index.js' implicitly has an 'any' type. Try `npm install @types/inp
..
我有此产品界面: export interface Product{ code: string; description: string; type: string; } 使用方法调用产品终结点的服务: public getProducts(): Observable { return this.http.get(`api
..
给定以下重载函数: foo(tool: 'a', poaram: boolean, poarama: number): boolean foo(tool: 'b', paramo: string, paramoa: string): boolean foo(tool: 'a' | 'b', ...args: any[]): boolean { if (tool === 'a') {
..
在“for of”循环内转换声明变量是否有更短、更简化的版本。 let array1: Array; for (let a of array1) { let ab: String = a; } 我知道强制转换整个数组是可行的,但如果我可以强制转换或设置声明变量“a”的数据类型,而不是强制转换整个数组,我会感到更高兴,这样的事情可能
..