Ever since template literals were introduced in Typescript (PR), we've had access to various useful functions in our types:
- Uppercase
- Lowercase
- Capitalize
- Uncapitalize
For more information, refer to the official documentation.
Although it may seem unlikely, I'm seeking clarification on a specific issue.
I have an interface with fixed properties and some that may vary. My goal is to extract the potentially evolving properties into a distinct type. These properties follow a pattern of incremental numbers from 1 to 3. To provide clarity, consider the example below:
interface A {
propA: string; // not needed
propB: string; // not needed
propC: string; // not needed
propD1: string;
propD2: string;
propD3: string;
propE1: string;
propE2: string;
propE3: string;
propF1: string;
propF2: string;
propF3: string;
}
Implementing this seems challenging, if not impossible... But ideally, I'd like a type similar to this:
MagicType<A>
should yield 'propD' | 'propE' | 'propF'
.
In essence, it should detect properties ending with 1
, 2
, or 3
.
While this task may exceed the capabilities of existing template literal functions (Uppercase
, Lowercase
, Capitalize
, Uncapitalize
), I wonder if there are provisions for creating custom intrinsic types at present?
Your insights and feedback would be greatly appreciated!