When analyzing my code for imports, I will specifically be searching for imports that do not end with -v3
. Here are some examples:
@ui/components <- this will match
@ui/components/forms/field <- this will match
@ui/components-v3 <- this should not match
@ui/components-v3/forms/field <- this should not match
My goal is to develop a typeguard that examines these import declarations, verifies that they follow a certain pattern, and then outputs an interpolated string. For instance,
function isDeprecatedComponentLibraryImport(importPath: string): importPath is `@ui/components${string}`;
The issue I am facing is that I need the opposite of this validation; I want it to confirm that the string matches @ui/components${string}
but does not match @ui/components-v3${string}
I could potentially create a function called complement
to determine the inverse, but this solution is not ideal as it only confirms what the string is not rather than what it actually is - which in this case should be @ui/components${string}
Can this be achieved in TypeScript?