type StartsWith<T extends string, U extends string> = T extends `${U}${infer Last}` ? true : false;
Solution by ZhipengYang0605 #33110
// your answers
type StartsWith<T extends string, U extends string> = T extends `${U}${infer R}` ? true : false
Solution by pea-sys #32851
// 你的答案
type StartsWith<T extends string, U extends string> = T extends `${U}${string}` ? true:false
Solution by shanguoteng #32815
type StartsWith<S1 extends string, S2 extends string> = S1 extends `${S2}${infer Rest}` ? true : false
type a = StartsWith<'abc', 'ac'> // expected to be false
type b = StartsWith<'abc', 'ab'> // expected to be true
type c = StartsWith<'abc', 'abcd'> // expected to be false
Solution by ZhulinskiiDanil #32712
type StartsWith<T extends string, U extends string> = T extends `${U}${infer _}` ? true : false
Solution by dev-hobin #32493
type StartsWith<T extends string, U extends string> = T extends `${U}${string}`? true:false
Solution by rkamely #32065
type StartsWith<T extends string, U extends string> = T extends `${U}${infer R}` ? true : false;
Solution by ricky-fn #31872
T extends `${U}${infer P}` ? true:false
Solution by Zhen-code #31801
type StartsWith<T extends string, U extends string> = T extends `${U}${infer T}`
? true
: false;
Solution by vipulpathak113 #31632
// your answers
type last = string
type StartsWith<T extends string, U extends string> = T extends `${U}${last}`? true:false;
Solution by kangaroona #31149
// your answers
I think it's a little bit overdone
type IsMore<A, B> = A extends `${infer AF}${infer AR}` ? B extends `${infer BF}${infer BR}` ? IsMore<AR, BR> : true : false;
type _StartWith<T extends string, U extends String> =
T extends `${infer TF}${infer TR}` ? U extends `${infer UF}${infer UR}` ?
TF extends UF ? _StartWith<TR, UR> : false : true : true;
type StartsWith<T extends string, U extends string> = IsMore<U, T> extends true ? false : _StartWith<T, U>;
Solution by chenqy-yh #31080
type StartsWith<T extends string, U extends string> =
T extends `${infer F}${infer Rest}`?
U extends `${infer UF}${infer URest}` ?
F extends UF ?
StartsWith<Rest, URest> :
false :
true :
U extends '' ?
true :
false
Solution by gearonix #30881
type StartsWith<T extends string, U extends string> = T extends `${U}${string}` ? true : false;
Solution by kai-phan #30836
type StartsWith<T extends string, U extends string> = T extends `${U}${infer Rest}` ? true : false
Solution by maximallain #30555
type StartsWith<T extends string, U extends string> = T extends `${U}${string}` ? true : false;
Solution by kanishev #29854
复用已有的ReplaceAll
type StartWith<T extends string, E extends string> = T extends `${E}${infer R}` ? true : false;
type a1 = StartWith<"abcd", "abcd">;
Solution by sundial-dreams #29482
Solution:
type StartsWith<T extends string, U extends string> = T extends `${U}${string}` ? true : false;
Solution by DmitriiBr #29353
type StartsWith<T extends string, U extends string> = T extends `${infer L}${infer R}`
? U extends `${infer Lm}${infer Rm}`
? [Lm] extends [never]
? true
: Lm extends L
? StartsWith<R, Rm>
: false
: true
: T extends U
? true
: false;
Solution by dmytro-shumak #29255
type StartsWith<T extends string, U extends string> = T extends ${U}${string}
? true
: false;
Solution by DoubleWoodLin #28690
type First<T extends string> = T extends `${infer F}${infer R}` ? F : never;
type Rest<T extends string> = T extends `${infer F}${infer R}` ? R : never;
type StartsWith<T extends string, U extends string> = U extends ''
? true
: First<T> extends First<U>
? First<T> extends never
? false
: StartsWith<Rest<T>, Rest<U>>
:false
Solution by breakinferno #28458
// your answers
type StartsWith<T extends string, U extends string> = T extends `${U}${infer R}` ? true : false;
Solution by GreattitJY #27657
type StartsWith<T extends string, U extends string> = T extends `${U}${string}` ? true : false
Solution by jjswifty #27624
type StartsWith<T extends string, U extends string> = T extends `${U}${string}` ? true : false;
Solution by jjswifty #27385
// your answers
type StartsWith<T extends string, U extends string> = T extends `${U}${string}` ? true : false
Solution by daiki-skm #27305
type StartsWith<T extends string, U extends string> = T extends `${U}${infer O}` ?
true : false
Solution by 8471919 #27207
type StartsWith<T extends string, U extends string> = T extends `${U}${string}` ? true : false;
Solution by RainbowIsPerfect #26998
type StartsWith<T extends string, U extends string> = T extends `${U}${string}` ? true : false
Solution by smileboyi #26915
type StartsWith<T extends string, U extends string> = T extends `${U}${infer _}` ? true : false;
Solution by rldnd #26853
type StartsWith<T extends string, U extends string> = T extends `${U}${infer _}`
? true
: false;
Solution by ryuji-1to #26817
type StartsWith<T extends string, U extends string> = T extends `${U}${infer R}`
? true
: false;
Solution by ZhipengYang0605 #26633