• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1describe("unittests :: internalApi :: typeParameterIsPossiblyReferenced", () => {
2        it("with type parameter aliasing", () => {
3            const content = `
4            declare function foo<T>(b: T, f: <T>(a: typeof b) => typeof a): typeof f;
5            `;
6            const host = new fakes.CompilerHost(vfs.createFromFileSystem(
7                Harness.IO,
8                /*ignoreCases*/ true,
9                {
10                    documents: [
11                        new documents.TextDocument("/file.ts", content)
12                    ],
13                    cwd: "/",
14                }
15            ));
16            const program = ts.createProgram({
17                host,
18                rootNames: ["/file.ts"],
19                options: { strict: true },
20            });
21            const checker = program.getTypeChecker();
22            const file = program.getSourceFile("/file.ts")!;
23            const typeQueryNode = (((file.statements[0] as ts.FunctionDeclaration) // function f<T>
24                .parameters[1] // f
25                .type! as ts.FunctionTypeNode) // <T>(a: typeof b) => typeof a
26                .type as ts.TypeQueryNode) // typeof a
27                ;
28            const typeParameterDecl = (file.statements[0] as ts.FunctionDeclaration).typeParameters![0]; // T in f<T>
29            const typeParameter = checker.getTypeAtLocation(typeParameterDecl)! as ts.TypeParameter;
30            const isReferenced = checker.isTypeParameterPossiblyReferenced(typeParameter, typeQueryNode);
31            assert.ok(isReferenced, "Type parameter is referenced in type query node");
32        });
33});
34