You can use Record<T, number>
(I recommend) or classic usage:
type test = <T extends string>(key: T, object: { [K in T]: number }) => void
Type objects don't work the same as JS objects.
EDIT
for more fields, use & (merge) operator:
type test = <T extends string>(key: T, object: { [K in T]: number } & {foo: "bar"}) => void
or (better)
type test = <T extends string>(key: T, object: Record<T, number> & {foo: "bar"}) => void
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…