Bas950
Bas950
Aarktype
Created by Bas950 on 9/6/2024 in #questions
string input, number output
is there something like
const input = '600';
const out = type('parse.number')(input)
console.log(out) // 600 (number)
const input = '600';
const out = type('parse.number')(input)
console.log(out) // 600 (number)
8 replies
Aarktype
Created by Bas950 on 8/15/2023 in #questions
Validate string is URL
What would be the easiest way to validate that the url in here is an actual valid url?
const button = type({
label: "2<=string<=32",
url: "2<=string<=512",
})
const button = type({
label: "2<=string<=32",
url: "2<=string<=512",
})
27 replies
Aarktype
Created by Bas950 on 6/27/2023 in #questions
Key not specified in type, but no problems
https://stackblitz.com/edit/mrvfrm-gduby2?file=type.ts How do I make it so I get a problem that foo is not in the type.
9 replies
Aarktype
Created by Bas950 on 6/27/2023 in #questions
Array/Object keys to type?
So I got this object:
export const supportedLanguages: {
afr: Language;
ara: Language;
ces: Language;
cmn: Language;
dan: Language;
deu: Language;
div: Language;
ell: Language;
fas: Language;
fra: Language;
gle: Language;
grc: Language;
hun: Language;
hye: Language;
jav: Language;
jpn: Language;
kat: Language;
kor: Language;
lat: Language;
lav: Language;
lit: Language;
mkd: Language;
nld: Language;
nno: Language;
nob: Language;
nor: Language;
pol: Language;
por: Language;
pus: Language;
ron: Language;
rus: Language;
slk: Language;
spa: Language;
srp: Language;
swe: Language;
tha: Language;
tur: Language;
ukr: Language;
urd: Language;
vie: Language;
};
export const supportedLanguages: {
afr: Language;
ara: Language;
ces: Language;
cmn: Language;
dan: Language;
deu: Language;
div: Language;
ell: Language;
fas: Language;
fra: Language;
gle: Language;
grc: Language;
hun: Language;
hye: Language;
jav: Language;
jpn: Language;
kat: Language;
kor: Language;
lat: Language;
lav: Language;
lit: Language;
mkd: Language;
nld: Language;
nno: Language;
nob: Language;
nor: Language;
pol: Language;
por: Language;
pus: Language;
ron: Language;
rus: Language;
slk: Language;
spa: Language;
srp: Language;
swe: Language;
tha: Language;
tur: Language;
ukr: Language;
urd: Language;
vie: Language;
};
Which as you can see has a few keys, you can pass these keys in an array, how would I make a ArkType for them automatically/dynamically since this object updates often. Without ArkType we currently use the following:
export type SupportedISOs = keyof typeof supportedLanguages;
export interface Options {
//Other options
languages: SupportedISOs[] // ("afr" | "ara" | "ces" | "cmn" | "dan" | "deu" | "div" | "ell" | "fas" | "fra" | "gle" | "grc" | "hun" | "hye" | "jav" | "jpn" | "kat" | "kor" | "lat" | "lav" | "lit" | "mkd" | "nld" | "nno" | "nob" | "nor" | "pol" | "por" | "pus" | "ron" | "rus" | "slk" | "spa" | "srp" | "swe" | "tha" | "tur" | "ukr" | "urd" | "vie")[];
}
export type SupportedISOs = keyof typeof supportedLanguages;
export interface Options {
//Other options
languages: SupportedISOs[] // ("afr" | "ara" | "ces" | "cmn" | "dan" | "deu" | "div" | "ell" | "fas" | "fra" | "gle" | "grc" | "hun" | "hye" | "jav" | "jpn" | "kat" | "kor" | "lat" | "lav" | "lit" | "mkd" | "nld" | "nno" | "nob" | "nor" | "pol" | "por" | "pus" | "ron" | "rus" | "slk" | "spa" | "srp" | "swe" | "tha" | "tur" | "ukr" | "urd" | "vie")[];
}
Can't figure out yet how I would make this in ArkType. Anyone have some ideas?
5 replies