cost 239 ms
TypeScript - 为什么在公共构造函数中有私有 class 时显示名称 - TypeScript - Why does a name get displayed when there is a private class inside a public constructor

我在下面的屏幕截图中有来自 W3Schools 的“自己尝试 TypeScript 参数属性”示例。 我有点困惑为什么当有这段代码时 Jane 的名字会显示在屏幕上。 我的理解是下面的代码将 aa 变量分配给 class Person console.log 代码使用此代码调用 getName( ...

在 Field Initializer 中使用 Constructor Shorthand 定义的字段 - Using fields defined by Constructor Shorthand in Field Initializer

我目前在将我的代码编译为 JS 后遇到问题,而在 ts-node 中运行相同的代码时不会发生这些问题。 假设以下代码: 好像ts-node是先初始化parameterProperty,然后用已经创建的值初始化字段。 然而,编译后的 JS 代码首先尝试初始化该字段,然后是 parameterPrope ...

Typescript & 反应 | 使用枚举设置 class 属性会引发错误 TS2349 - Typescript & React | Setting class property with an Enum is throwing error TS2349

我需要一些帮助。 我的目标是创建一个可以更改其属性的class C_GenericTask 。 这些属性之一是具有以下属性的枚举 E_TaskState :TODO、DOING 和 DONE。 但是当我尝试使用 C_GenericTask 的设置器时,typescript 会抛出此错误: TS2 ...

为什么一个类中的这个方法没有扩展到下一个类,而是我看到 - [Function (anonymous)] in TypeScript - Why is this method in a class is not getting extended to the next class, instead I see - [Function (anonymous)] in TypeScript

register() 与 Person 类一起工作正常,当我在 Person 类之后 console.log 时,我确实看到了 return 语句 后来我将它扩展到我的 Employee 类,但是当我在那里 console.log 它时,我看到 - [Function (anonymous)] 而 ...

当我扩展内置数组 class 时,如何使用实用程序类型或类型参数进行类型推断? - How to get type inference using a utility type, or type parameter, when I extend the built-in array class?

在扩展数组中定义类成员的类型 Class 所以在下面,您可以看到我通过WillyWonka class 扩展了数组 class。问题是,当我如下所示执行此操作时,我没有对存储在数组中的项目进行类型推断。 我最担心的是数组原型实现了奇异的属性,使其成为一个特殊的、有点独特的 class 来扩展。 我 ...

Typescript:将类数组类型转换为构造类数组类型 - Typescript: converting type of array of classes to type of array of constructed classes

有一个问题我一直在努力解决。 我有一个 function,里面放了两个 arguments: 类- 类数组映射器- function 采用这些类的实例数组。 想象一下这样的 function: 我怎么能为此创建一个 typescript 声明,以确保映射器将始终接受类实例的数组。 示例用法: 所以我 ...

如何在 Typescript 中正确扩展通用 class? - How to properly extend a generic class in Typescript?

我创建了一个 class: 这个 class 有以下方法: 我试图用一个只有一个通用的 class 来扩展这个 class ,如下所示: 但是一旦我尝试打电话: 我得到错误: 我理解这个错误是由于将第二个泛型设置为keyof T而不是K extends keyof T之类的东西引起的,但是是否可以 ...

条件语句中类型推断的 TS 错误,当条件使用函数调用的结果而不是布尔表达式时 - TS Error with Type Inference within Conditional Statement, when the condtional is using the result of a function call instead of a boolean expression

我有以下用于链接列表类的 TypeScript 类,并且一切正常。 现在我想创建一个辅助函数 isEmpty() 来检查链表是否为空,如下所示。 然后改变 addLast() 函数如下 但这会导致错误,这是有道理的,因为现在我猜 TS 不知道我的条件的实现,只知道结果并且不知道 this ...

通用 Class 的可选方法参数的类型 - Type for Optional Method Argument of Generic Class

我想知道是否有一种方法可以声明具有默认泛型类型的泛型 class : 默认情况下将允许调用 class 的方法而不通过 arguments 如果定义了另一个泛型类型,则只有在传递泛型类型的参数时才能调用该方法。 伪代码class ClassA<MyGenericType = OptionalA ...


 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM