-
Notifications
You must be signed in to change notification settings - Fork 517
/
testRecursiveDomain.ts
51 lines (43 loc) · 2.01 KB
/
testRecursiveDomain.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
/**
* This file exists and is package exported to aid in testing of exporting recursive types across package boundaries.
* Sometimes when TypeScript generates d.ts files, they type check significantly differently than the original source (One example of this: https://github.com/microsoft/TypeScript/issues/20979).
* Unfortunately our recursive schema types are an example of types that have this kind of issue: the d.ts files tend to get "any" instead of the recursive type reference.
* Currently we do not have tooling in place to test this in our test suite, and exporting these types here is a temporary crutch to aid in diagnosing this issue.
*/
import { AllowedTypes, FieldKinds, FieldSchema, SchemaBuilder } from "../feature-libraries";
import { areSafelyAssignable, isAny, requireFalse, requireTrue } from "../util";
import * as leaf from "./leafDomain";
const builder = new SchemaBuilder({ scope: "Test Recursive Domain", libraries: [leaf.library] });
/**
* @alpha
*/
export const recursiveStruct = builder.structRecursive("struct", {
recursive: FieldSchema.createUnsafe(FieldKinds.optional, [() => recursiveStruct]),
number: SchemaBuilder.fieldRequired(leaf.number),
});
// Some related information in https://github.com/microsoft/TypeScript/issues/55758.
function fixRecursiveReference<T extends AllowedTypes>(...types: T): void {}
const recursiveReference = () => recursiveStruct2;
fixRecursiveReference(recursiveReference);
/**
* @alpha
*/
export const recursiveStruct2 = builder.struct("struct2", {
recursive: FieldSchema.create(FieldKinds.optional, [recursiveReference]),
number: SchemaBuilder.fieldRequired(leaf.number),
});
type _0 = requireFalse<isAny<typeof recursiveStruct2>>;
type _1 = requireTrue<
areSafelyAssignable<
typeof recursiveStruct2,
ReturnType<(typeof recursiveStruct2.structFieldsObject.recursive.allowedTypes)[0]>
>
>;
/**
* @alpha
*/
export const library = builder.finalize();