#Use func argument as type definition possible without generic?

1 messages · Page 1 of 1 (latest)

jolly domeBOT
#
nnry#0

Preview:ts function a<T>(key: string, value: T) { const b: {[key]: T} = {} }

frail skiff
#

well it should be [key]?: T or something because i'm creating a empty object for now

leaden glen
#

You can't really represent that type, because the value of key is determined at runtime

#

So key would need to be something more specific, or alternatively b would need to be wider to accommodate