#array mapping and noUncheckedIndexedAccess

5 messages · Page 1 of 1 (latest)

uncut bloomBOT
#
ricmed#0

Preview:```ts
function PrivateKs(strS: string[]): symbol[] {
return strS.map(str => Symbol(str))
}

// I know PrcClass is symbol, not symbol | undefined
// could cast here with [symbol] but would prefer a generalized solution inside the function
const [PrcClass] = PrivateKs(["PrcClass"])
...```

#
nonspicyburrito#0

Preview:```ts
function PrivateKs<const T extends readonly string[]>(
strS: T,
): {
[K in keyof T]: symbol
} {
return strS.map((str) => Symbol(str)) as never
}

// I know PrcClass is symbol, not symbol | undefined
// could cast here with [symbol] but would prefer a generalized solution inside the function
...```

frosty cape
#

You could do this, maybe there's a better solution though.

glacial blaze
#

either way, I just found out I can't have those symbols as class field which is what I wanted to do

#

thanks anyways!