flatMorph in a type

I'm trying to use flatMorph to generate dynamic template literal keys for a type but it's becoming unknown.
const test = flatMorph(
Array.from({ length: 15 }, (_, i) => i + 1),
(i, v) => [`test_${i}` as const, 'string'],
);
const a = type(test)
const test = flatMorph(
Array.from({ length: 15 }, (_, i) => i + 1),
(i, v) => [`test_${i}` as const, 'string'],
);
const a = type(test)
The types are:
const test: {
[x: `test_${number}`]: string;
}

const a: Type<unknown, {}>
const test: {
[x: `test_${number}`]: string;
}

const a: Type<unknown, {}>
Why is a not preserving the type?
2 Replies
TizzySaurus
TizzySaurus6d ago
Surely the 'string' has to be const too? Have you tried that? I also seem to remember template literals not being supported, although not certain of that What type were you expecting?
outsideurimagination
Thanks but that doesn't change anything. I want to have keys of an object match the template literal and be able to assert their values' types

Did you find this page helpful?