Type Script 中 如何寫 overload
在TypeScript 中視可以寫 overload TypeScript 是支援 overload但是非常奇葩 又愛又恨 可以更短的寫出來 但是我覺閱讀性卻欠佳 如下方所表示 Code Like this import { DateTimeFormatter, LocalDateTime } from "@js-joda/core" ; export class DBUtils { public static toDateString(inDateStr: string, formate : string): string; public static toDateString(inDateStr: string, formate : DateTimeFormatter): string; public static toDateString(d: Date ): string; public static toDateString(arg1: string | Date , arg2?: string | DateTimeFormatter): string { if ( typeof arg1 === 'string' && typeof arg2 === 'string' ) { let ldt: LocalDateTime = LocalDateTime.parse(arg1, DateTimeFormatter.ofPattern(arg2)); return ldt.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME); } if ( typeof arg1 === 'string' && arg2 instanceof DateTimeFormatter) { let ldt: LocalDateTime = LocalDateTime.parse(arg1, arg2); ...