In the process of building a tool (partly to test its functionality), I am developing a way to condense a set of TypeScript definitions into a clean d.ts file, while ignoring unnecessary helper types used for reshaping data. This approach is proving quite effective so far, except for one frustrating limitation.
Unfortunately, I have encountered an issue where I cannot determine if one type literal extends another - something that should be relatively straightforward.
import ts from 'typescript';
const program = ts.createProgram([], {})
const checker = program.getTypeChecker();
// { result: any }
const node1 = ts.factory.createTypeLiteralNode([
ts.factory.createPropertySignature([], "result", undefined, ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword))
]);
// { something: any }
const node2 = ts.factory.createTypeLiteralNode([
ts.factory.createPropertySignature([], "something", undefined, ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword))
]);
checker.isTypeAssignableTo(
checker.getTypeAtLocation(node1),
checker.getTypeAtLocation(node2)
)
I have attempted various approaches to solve this problem, such as omitting getTypeAtLocation
. The method isTypeAssignableTo
successfully compares false/true or string/number, but not literals in this context.
It is possible that I am missing something obvious here, either because the solution is simple or incredibly complex and perhaps not worth pursuing further.