Skip to content

Commit 0b01d61

Browse files
committed
Workaround for microsoft/TypeScript#4888 using
technique in microsoft/TypeScript#4521
1 parent 3c3ae26 commit 0b01d61

16 files changed

+244
-33
lines changed

js/main/Db3.d.ts

+21-12
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ declare module Db {
2222
interface Entity {
2323
}
2424
/**
25-
* Definition of an entity constructor, just to mane things.
25+
* Definition of an entity constructor, just to name things.
2626
*/
2727
interface EntityType<T extends Entity> {
2828
new (): T;
2929
}
30+
interface EntityTypeProducer<T extends Entity> {
31+
(): EntityType<T>;
32+
}
3033
/**
3134
* Internal module, most of the stuff inside this module are either internal use only or exposed by other methods,
3235
* they should never be used directly.
@@ -1257,11 +1260,17 @@ declare module Db {
12571260
class MetaDescriptor {
12581261
localName: string;
12591262
remoteName: string;
1260-
ctor: EntityType<any>;
1263+
/**
1264+
* This could be either a class constructor (EntityType), or an anonymous function returning a costructor
1265+
* (EntityTypeProducer). Code for resolving the producer is in the cotr getter. This producer stuff
1266+
* is needed for https://github.com/Microsoft/TypeScript/issues/4888.
1267+
*/
1268+
private _ctor;
12611269
classMeta: ClassMetadata;
12621270
getTreeChange(md: Metadata): ClassMetadata;
12631271
getRemoteName(): string;
12641272
setType(def: any): void;
1273+
ctor: EntityType<any>;
12651274
named(name: string): MetaDescriptor;
12661275
setLocalName(name: string): void;
12671276
createEvent(allMetadata: Metadata): GenericEvent;
@@ -1357,22 +1366,22 @@ declare module Db {
13571366
}
13581367
function bind(localName: string, targetName: string, live?: boolean): Internal.IBinding;
13591368
function sortBy(field: string, desc?: boolean): Internal.SortingData;
1360-
function embedded(def: EntityType<any>, binding?: Internal.IBinding): PropertyDecorator;
1361-
function reference(def: EntityType<any>, project?: string[]): PropertyDecorator;
1362-
function map(valueType: EntityType<any>, reference?: boolean, sorting?: Internal.SortingData): PropertyDecorator;
1363-
function set(valueType: EntityType<any>, reference?: boolean, sorting?: Internal.SortingData): PropertyDecorator;
1364-
function list(valueType: EntityType<any>, reference?: boolean, sorting?: Internal.SortingData): PropertyDecorator;
1369+
function embedded(def: EntityType<any> | EntityTypeProducer<any>, binding?: Internal.IBinding): PropertyDecorator;
1370+
function reference(def: EntityType<any> | EntityTypeProducer<any>, project?: string[]): PropertyDecorator;
1371+
function map(valueType: EntityType<any> | EntityTypeProducer<any>, reference?: boolean, sorting?: Internal.SortingData): PropertyDecorator;
1372+
function set(valueType: EntityType<any> | EntityTypeProducer<any>, reference?: boolean, sorting?: Internal.SortingData): PropertyDecorator;
1373+
function list(valueType: EntityType<any> | EntityTypeProducer<any>, reference?: boolean, sorting?: Internal.SortingData): PropertyDecorator;
13651374
function root(name?: string, override?: string): ClassDecorator;
13661375
function discriminator(disc: string): ClassDecorator;
13671376
function override(override?: string): ClassDecorator;
13681377
function observable(): PropertyDecorator;
13691378
function ignore(): PropertyDecorator;
13701379
module meta {
1371-
function embedded(def: any, binding?: Internal.IBinding): Db.Internal.EmbeddedMetaDescriptor;
1372-
function reference(def: any, project?: string[]): Db.Internal.ReferenceMetaDescriptor;
1373-
function map(valuetype: EntityType<any>, reference?: boolean, sorting?: Internal.SortingData): Db.Internal.MapMetaDescriptor;
1374-
function set(valuetype: EntityType<any>, reference?: boolean, sorting?: Internal.SortingData): Db.Internal.SetMetaDescriptor;
1375-
function list(valuetype: EntityType<any>, reference?: boolean, sorting?: Internal.SortingData): Db.Internal.ListMetaDescriptor;
1380+
function embedded(def: EntityType<any> | EntityTypeProducer<any>, binding?: Internal.IBinding): Db.Internal.EmbeddedMetaDescriptor;
1381+
function reference(def: EntityType<any> | EntityTypeProducer<any>, project?: string[]): Db.Internal.ReferenceMetaDescriptor;
1382+
function map(valuetype: EntityType<any> | EntityTypeProducer<any>, reference?: boolean, sorting?: Internal.SortingData): Db.Internal.MapMetaDescriptor;
1383+
function set(valuetype: EntityType<any> | EntityTypeProducer<any>, reference?: boolean, sorting?: Internal.SortingData): Db.Internal.SetMetaDescriptor;
1384+
function list(valuetype: EntityType<any> | EntityTypeProducer<any>, reference?: boolean, sorting?: Internal.SortingData): Db.Internal.ListMetaDescriptor;
13761385
function observable(): Db.Internal.ObservableMetaDescriptor;
13771386
function ignore(): Db.Internal.IgnoreMetaDescriptor;
13781387
function define(ctor: EntityType<any>, root?: string, discriminator?: string, override?: string): void;

js/main/Db3.js

+26-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/main/Db3.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/test/Db3ForwardRight.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export = ForwardWrong;
2+
declare module ForwardWrong {
3+
class A {
4+
prop: B;
5+
}
6+
class B {
7+
}
8+
}

js/test/Db3ForwardRight.js

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/test/Db3ForwardRight.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/test/Db3ForwardWrong.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export = ForwardWrong;
2+
declare module ForwardWrong {
3+
class A {
4+
prop: B;
5+
}
6+
class B {
7+
}
8+
}

js/test/Db3ForwardWrong.js

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/test/Db3ForwardWrong.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/test/Db3Tests.js

+26-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/test/Db3Tests.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)