Skip to content

Instantly share code, notes, and snippets.

@fr1sk
Created September 14, 2022 14:09
Show Gist options
  • Save fr1sk/47314ccf1283eeacbb678409f7ced3d0 to your computer and use it in GitHub Desktop.
Save fr1sk/47314ccf1283eeacbb678409f7ced3d0 to your computer and use it in GitHub Desktop.
pick-type-problem
class TestDto {
@ApiProperty({ type: String, required: true })
@IsString()
@IsDefined()
id: string;
@ApiProperty({ type: String, required: true })
@IsString()
@IsDefined()
testId: string;
@ApiProperty({ type: String, required: true })
@IsNumber()
value: number;
}
const SMALLER_TEST_DTO_REQUIRED_FIELDS: Array<keyof TestDto> = ["id", "testId"];
class SmallerTestExpectedDto extends PickType(TestDto, ["id", "testId"]) {}
class SmallerTestUnexpectedDto extends PickType(TestDto, SMALLER_TEST_DTO_REQUIRED_FIELDS) {}
const smallerTestExpected: SmallerTestExpectedDto = {
id: "id",
testId: "test",
};
const smallerTestUnexpected: SmallerTestUnexpectedDto = {
id: "id",
testId: "test",
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment