If you want to declare a type that has the same property name as a string constant you could use the following syntax (lookup type syntax)
const myProp = 'my prop';
type Foo = {
[P in typeof myProp]: string
};
const test: Foo = {
[myProp]: myProp
}
If you want to have several of these keys you can use a union type :
const myProp = 'my prop';
const otherProp = "otherProp"
type Foo = {
[P in (typeof myProp | typeof otherProp)]: string
};
const test: Foo = {
[myProp]: myProp,
[otherProp]: otherProp
}
The typescript default libraries, actually provides a type that is equivalent to the above lookup type declaration, named Record. Using this you could write your type as:
type Foo2 = Record<typeof myProp, string>;