0

I am trying to generate a type using a value provided by a generic. Here is my attempt that doesn't compile

type modifyKey<T extends 'a' | 'b'> = {
    [id: `${T}changed`]: T | string;
    another: number
}

1 Answer 1

2
type modifyKey<T extends 'a' | 'b'> = {
  [Prop in T as `${T}changed`]: T | string;
} & {
   another: number
}

// type Result = { achanged: string;   bchanged: string; another: number; }
type Result = modifyKey<'a' | 'b'> 

Here you can find docs for property renaming

P.S. According to convention, type name should be capitalized

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.