我正在用three.d.ts develop分支编译TypeScript (可从获得)。我得到以下错误:
Types of static property 'Utils' of class 'THREE.Shape' and class 'THREE.Path'
are incompatible
问题是
Shape定义了一个静态Utils类
Shape间接地继承了Curve
Curve还定义了一个带有与Shape.Utils无关的签名的静态Utils类。
根据语言规范是不正确的。概括地说,three.d.ts包含如下代码:
d
我想从typescript代码库中建模一些接口和类。我想知道在Java中对typescript联合进行建模的最佳方法。像这样的东西-
export type a = b | c | d | e | f;
export type b = {
..
}
export type c = {
..
}
..
用Java对此进行建模的最佳方式是什么?
例如:Class A = Class B or Class C or Class D;这意味着A可以是这些类中任何一个的对象。我正在寻找一个类的解决方案。但另一个例子是。export type numberString = string
我试图通过在接口中扩展来使用多个类。使用typescript,但得到以下错误: [ERR]: employee.eat is not a function 这是我的尝试: class Animal {
species: string;
id: number = 0;
constructor(species: string) {
this.species = species
}
eat(fruit:string):void{
console.log('eating is healty' + fruit)
我有以下TypeScript代码: class ClassA {
field1: any;
}
const SomeClassAsA = diContainer.get('SomeClass') as ClassA;
class ClassB extends ClassA {} // works
class ClassB extends SomeClassAsA {} // error: Type ClassA is not a constructor function type 为什么可以用ClassA扩展ClassB,而不能用其他被转换为ClassA的对象来扩展呢
我是angular (TypeScript)的新手,我想实现两个类之间的合成。我怎样才能做到这一点呢?
在c#中,如果我有像A和B这样的两个类,那么我实现如下的组合
class A
{
int ID {get;set;}
List<B> lstClassB {get;set;}
}
class B {
int ID {get;set;}
}
如何在TypeScript中使用此功能,如
export class A
{
ID :int;
lstClassB : ////what should I write here?
}
export class B
我用TypeScript编写了一个泛型类,我想要定义一个新类型,这样可以更容易地重用类名。
class Foo<T> {
...
}
type FooNumber = Foo<number>;
type FooString = Foo<string>;
如果我创建一个FooNumber对象,就会得到以下错误消息:
new FooNumber();
'FooNumber' only refers to a type, but is being used as a value here.ts(2693)
在C++中,我会使用decltype。这
在Javascript中,类继承静态方法,但是子类方法隐藏具有相同名称的超类方法,而不是重载它们。所以你可以做这样的事情:
class A {
static foo(a) { ... }
}
class B extends A {
static foo(a, b) { ... }
}
您可以调用A.foo(a)或B.foo(a,b),它将按照预期运行。不幸的是Typescript不喜欢这样,它似乎假设同样的规则适用于例如方法,即所有的方法都是虚拟的。因此,尝试在.d.ts文件中表示上述内容:
export class A {
static foo(a: string):
出于各种原因,我正在转向Typescript,到目前为止,我对它非常满意。
我遇到的问题之一是验证传递给函数的参数是否扩展了另一个类。
例如:
class Foo {
public $xyz
}
class Bar {
constructor(model: extends Foo)
}
class Baz extends Foo {}
除了Baz之外,许多类都可以扩展foo,但它们都具有相同的属性。我需要确保传递给构造函数Bar的model参数的类正确地扩展了Foo。
我如何才能做到这一点?
(请原谅上面可怕的伪代码)
如果我的方法是错误的,我也很想听听我能做些什么来解决这
根据docs的说法,“TypeScript中的类型兼容性是基于结构子类型”。所以这是有可能的:
type Person: {
name: string;
}
const developer = {
name: 'Joe',
language: 'Typescript',
}
// this is ok because Person is a subtype of typeof developer
const otherDeveloper: Person = developer; // who writes code like that?!
这有许
我试图在TypeScript中实现服务定位器模式。
这是我的代码:
//due to only partial knowledge of TypeScript
private static serviceMap: Map<string, any>;
public static get<T>(): T {
// firstly lazily register all of the necessary services if this is the
// first time calling get.
if(this.serviceMap
假设我有一个类装饰器,它向一个类添加了一些方法。
function decorator(target) {
target.prototype.method = function() {};
}
@decorator
class Test {
constructor() {
this.method() <------- Property method does not exists on type Test
}
}
如果我有能力添加装饰器,但是typescript无法识别它们,那它就毫无价值了。
有办法解决这个问题吗?
目标是在我的TypeScript代码中进行代码分割。
我使用(实验性的)装饰器来支持从模型到持久存储的类似ORM的数据映射。其中一种类型需要用表的名称参数化装饰器,该表将存储该类型的实体。为了进行代码拆分,我将域模型提取为一个单独的文件(entity-model.ts):
/* I am using dynamodb-data-mapper */
import {
table,
hashKey,
attribute
} from '@aws/dynamodb-data-mapper-annotations'
export class Entity {
/*
我有一个angular2项目,其中我使用http模块发出get请求。该对象是从服务器检索的,并且显然被正确地反序列化到其相应的typescript对象中,但是当我尝试访问属性时,它返回undefined,即使在试图访问这些属性之前将对象打印到控制台时,数据似乎也存在。
这是我的get请求方法的样子。
getDataForEmployee(data){
var url = this.active+"/guest/"+data;
var headers = new Headers();
headers.append("Content-Type
从TypeScript开始,我尝试使用keyof来定义类的动态属性:
type UserType = {
id: number,
name: string,
}
class Domain<T> {
_data: T;
[K in keyof T]: T[K]; // Does not build:
// (1) A computed property name must be of type
// 'string', 'number
在关于函数和lambda的kotlin文档中找到了这个 class IntTransformer: (Int) -> Int {
override operator fun invoke(x: Int): Int = TODO()
}
val intFunction: (Int) -> Int = IntTransformer() 在这个page中,它说你可以像接口一样实现函数类型到类。它怎麽工作?你能给我一些每个部分的解释,并给我一个例子,这是如何做到的? 据我所知,IntTransformer扩展/实现了匿名函数,该函数以整型为参数和输出类型,但我仍然不知道它是如何
在下面的代码中,我尝试创建一个访问给定输入的data属性的类型安全函数。我的目标是避免在任何地方重复对data的访问,为此,我希望将样板保持在最小(例如,我希望TypeScript推断尽可能多的类型)。
interface User {
name: string
}
interface HttpResponse<T> {
data: T
status: number
}
type HttpPromise<T> = Promise<HttpResponse<T>>
function fetch<T>(url