refactor: remove side effects

This commit is contained in:
Simon Chan 2025-03-13 17:31:51 +08:00
parent a335c1495c
commit 92511c63de
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD
12 changed files with 241 additions and 194 deletions

View file

@ -25,19 +25,17 @@ export interface String {
): Field<string, KOmitInit, KS>;
}
// Rollup doesn't support `/* #__NO_SIDE_EFFECTS__ */ export const a = () => {}
/* #__NO_SIDE_EFFECTS__ */
function _string(
// Prettier will move the annotation and make it invalid
// prettier-ignore
export const string: String = (/* #__NO_SIDE_EFFECTS__ */ (
lengthOrField: string | number | BufferLengthConverter<string, unknown>,
): Field<string, string, Record<string, unknown>> & {
as: <T>(infer: T) => Field<T, string, Record<string, unknown>>;
} {
} => {
const field = buffer(lengthOrField as never, {
convert: decodeUtf8,
back: encodeUtf8,
});
(field as never as { as: unknown }).as = () => field;
return field as never;
}
export const string: String = _string as never;
}) as never;