Issue
I know that I can use utility types in type script, e.g. Pick, to build other types. But let's say after I Pick some of the properties from an interface, I want that new type to extend another interface.
export interface ICreateRequestVo {
};
export interface IFoo {
foo: string;
bar: string;
};
export type FooRequestVo = Pick<IFoo, 'foo'>;
Now when I try to make FooRequestVo extends ICreateRequestVo, I get the following error:
export type FooRequestVo = Pick<IFoo, 'foo'> extends ICreateRequestVo;
TS1005: '?' expected.
Solution
You probably want a type intersection:
type FooRequestVo = Pick<IFoo, 'foo'> & ICreateRequestVo;
Regarding the error: TypeScript thinks you want to use a conditional type such as:
type TypeE = TypeA extends TypeB ? typeC : typeD
Answered By - Conaclos
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.