Skip to content

Commit

Permalink
review-fix:ハイフンがない郵便番号とハイフンがある郵便場号を区別するよう型を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
marumoto-goq committed May 2, 2024
1 parent 9b42acd commit cb19868
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/test/constants/address.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, UnHyphenatedZipCode } from '../type/type';
import { UnHyphenatedZipCodeAddress } from '../type/type';

export const addresses: Address<UnHyphenatedZipCode>[] = [
export const addresses: UnHyphenatedZipCodeAddress[] = [
{
zipcode: '7340001',
pref: '広島県',
Expand Down
4 changes: 2 additions & 2 deletions src/test/constants/addressIncludingHyphenDataList.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Address, HyphenatedZipCode } from '../type/type';
import type { HyphenatedZipCodeAddress } from '../type/type';

export const addressIncludingHyphenDataList: Address<HyphenatedZipCode>[] = [
export const addressIncludingHyphenDataList: HyphenatedZipCodeAddress[] = [
{
zipcode: '734-0001',
pref: '広島県',
Expand Down
15 changes: 11 additions & 4 deletions src/test/type/type.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
export type Address<ZipCode extends string> = {
zipcode: ZipCode;
export type UnHyphenatedZipCodeAddress = {
zipcode: string;
pref: string;
city: string;
town: string;
};

export type UnHyphenatedZipCode = `${string}`;
export type HyphenatedZipCode = `${string}-${string}`;
export type HyphenatedZipCodeAddress = {
zipcode: `${string}-${string}`;
pref: string;
city: string;
town: string;
};

export type UnHyphenatedZipCode = `${number}`;
export type HyphenatedZipCode = `${number}-${number}`;
9 changes: 4 additions & 5 deletions src/test/utils/goqZipCode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {
Address,
HyphenatedZipCode,
UnHyphenatedZipCode,
HyphenatedZipCodeAddress,
UnHyphenatedZipCodeAddress,
} from '../type/type';

export const goqZipCode = {
Expand Down Expand Up @@ -33,8 +32,8 @@ export const goqZipCode = {

convertHyphenatedZipCode: function (
hasOptionHyphen: boolean,
addresses: Address<string>[]
): Address<UnHyphenatedZipCode | HyphenatedZipCode>[] {
addresses: UnHyphenatedZipCodeAddress[]
): HyphenatedZipCodeAddress[] | UnHyphenatedZipCodeAddress[] {
if (hasOptionHyphen === false) {
return addresses;
}
Expand Down

0 comments on commit cb19868

Please sign in to comment.