How to validate `Record<string, string>`?

My naïve attempt:
const Response = type({
"*": "string",
});
type Response = typeof Response.infer;

const createResponse = (): Response => {
const values: Record<string, string> = {
value1: "one",
value2: "two",
};
return values;
};
const Response = type({
"*": "string",
});
type Response = typeof Response.infer;

const createResponse = (): Response => {
const values: Record<string, string> = {
value1: "one",
value2: "two",
};
return values;
};
This results in error:
Property '"*"' is missing in type 'Record<string, string>' but required in type '{ "*": string; }'.
Property '"*"' is missing in type 'Record<string, string>' but required in type '{ "*": string; }'.
3 Replies
SynthLuvr
SynthLuvrOP6mo ago
const Response = type({
"[string]": "string",
});
const Response = type({
"[string]": "string",
});
^ works makes sense
TizzySaurus
TizzySaurus6mo ago
Soon™️ type("Record<string, string>") will work too :) But yeah, for now you have to use index signatures
ssalbdivad
ssalbdivad6mo ago
It will be genuinely soon! I just want to get the docs done first for the stuff that is already there like this 😛 Then finishing up generics and pattern matching will be like my victory lap
Want results from more Discord servers?
Add your server