typescript相关内容
我编写了一个拦截器来为我刷新令牌。但使用我检查的调试器,它根本不会进入SwitchMap,请求也不会再次发送它。 有人知道问题是从哪里来的吗? import {HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse} from '@angular/common/http
..
我正在尝试制作以下内容 import { IValueObject } from "../../shared/domain/IValueObject"; import { AbstractNanoidGenerator } from "../../shared/infrastructure/AbstractNanoidGenerator"; export class CompanyID e
..
我使用的是ANGLE中的不同环境,存储在环境文件夹中,如下所示: environment.ts environment.dev.ts environment.prod.ts 在环境.ts文件中,我有: export const environment = { production: false, environment: 'Development', advanced:
..
我有以下模块定义,它包含一个MetaData类型和一个将任意名称映射到子模块/嵌套模块的对象: type Module = { metaData: T; children: C; }; type Children = { [key: string]: Module; } type ExtractMe
..
给出一个框: type A = {readonly id: 'A'} type B = {readonly id: 'B'} type Value = A | B class Box { constructor(public value: T) {} } 我想创建一个函数merge: let a
..
我有这个类定义 class abstract MyClass { } 可用作 class MyOtherClass extends MyClass { } 但是,我想限制此类与所有简单类型的使用: class MyOtherClass extends MyClass { } //
..
我是打字新手,还处于学习阶段。我正在尝试创建泛型以强制执行以下条件 假设我有一个空对象 const data = {} 我需要创建将检查以下条件的泛型 如果是,则检查是否为对象,然后检查其中是否有数据,否则返回FALSE 提前谢谢 推荐答案 您可以使用此实用程序检查对象类型是否为空: // credits goes to https://github.
..
我想根据同级属性缩小函数参数的类型。我知道存在类型会有帮助,但它们不可用,所以我使用了一个助手函数。多亏了评论中的jcalz,我现在有了这个 // helper function function helper(o: { choices: T; func: (opts: T[number]) => T[number]; })
..
我在一家工厂工作;我最终需要向this answer和this answer添加自定义方法,我们能够使其工作几乎如预期的。 几乎是因为它只适用于没有任何必需参数的方法;如果我们尝试添加至少具有一个必需参数的方法,则会收到编译错误。 我尝试将REST参数数组同时添加到method参数和M类型的声明中(见下文),但仅在调用方法时有用。 (this: E & S, ...args: u
..
JUXT调用函数数组以返回值的数组。文档:ramdaclojure 我正在尝试键入不带覆盖的数据优先版本,但我想不出如何map the tuple of functions to their return values。这是我所拥有的: type JuxtFn = (x: T) => any function juxt[]>(
..
我有一个类型,如果我不给任何值,我想用any将对象键定义为可选 type OptionalData = T extends undefined ? { data?: any } : { data: T }; export type DataObject = { item?: string | null; } & OptionalData; 在我将泛型
..
很抱歉标题很难,但请看以下最低限度的表示: // We define a couple of symbols const A: unique symbol = Symbol(); const B: unique symbol = Symbol(); // And create an "enum" of them const Fs = { A, B } as const; // T
..
我想将类型定义为显式属性和泛型类型的混合,在匹配键的情况下,显式属性优先。下面是我的尝试,但我在指示的行上收到错误-有人能解释一下这是为什么吗?或者这是TSC/编译器错误吗? // Takes properties in A and B. For matching properties, the types in A are used. type Mix = { [K in
..
我有一个组件,我正在传递一个名为HtmlTag的道具,并且根据它的值,我想用基于html标记的正确道具来扩展道具接口。 我尝试创建一个充当映射的类型,然后尝试扩展它,例如 type AllAttrs = { a: AnchorHTMLAttributes, button: ButtonHTMLAttributes } 目前正在尝试以下操作 interface Prop
..
我需要基于受约束的泛型创建新类型。新类型应该与泛型具有相同的键,使它们成为可选的,并将它们映射到一个数字。 我的第一个方法是使用Partial>,但由于某种原因导致错误Type [...] is not assignable to type 'Partial>'.。 所以
..
我是用这个基本概念的更复杂版本来问这个问题的 版本:Can Generic JSX.Elements work in Typescript 我将范围缩小到核心元素: 这是Object A,它从TypeA获取参数 type TypeA = { label: string value: number } const ObjA = ({ label, value }:Type
..
已经提出了几个这样的问题。但我认为这个更具体一些。 请参见此示例: interface Body { legs: number; } interface Kingdom { animalia: { sound: string; // meow.. body: Body; }; } function GetBody
..
在大多数情况下,具有泛型类型的函数可以从参数中推断泛型类型。但是,如果参数是泛型类型既是参数的一部分又是返回值的函数,则有时不会推断该泛型类型。 简化的示例,有一个用于存储项目的类,其中项目的一些属性是自动生成的(例如,ID是自动生成的数据库): /** * Stores items of type T */ class Store { /** * Return
..
我注意到
泛型通常是没有意义的,因为基本上javascript中的所有东西都是对象。大多数文本都是使用.toString方法的对象。字符串是具有.long属性的对象,等等。我只喜欢
,但很好奇其他人注意到了什么。 我现在没有好的例子,我更多的是想听听别人的经验。 推荐答案 有关详细信息,请参阅"The object Type in TypeS
..
我正在尝试使用函数组合将行为添加到具有Mixin的对象: const pipe = (...funcs: ((...args: any[]) => any)[]) => (initial: any) => funcs.reduce((object, fn) => fn(object), initial); const speakMixin = (obj: T): T & { s
..