| 1831 | } |
| 1832 | |
| 1833 | export class ZodBoolean extends ZodType<boolean, ZodBooleanDef, boolean> { |
| 1834 | _parse(input: ParseInput): ParseReturnType<boolean> { |
| 1835 | if (this._def.coerce) { |
| 1836 | input.data = Boolean(input.data); |
| 1837 | } |
| 1838 | const parsedType = this._getType(input); |
| 1839 | |
| 1840 | if (parsedType !== ZodParsedType.boolean) { |
| 1841 | const ctx = this._getOrReturnCtx(input); |
| 1842 | addIssueToContext(ctx, { |
| 1843 | code: ZodIssueCode.invalid_type, |
| 1844 | expected: ZodParsedType.boolean, |
| 1845 | received: ctx.parsedType, |
| 1846 | }); |
| 1847 | return INVALID; |
| 1848 | } |
| 1849 | return OK(input.data); |
| 1850 | } |
| 1851 | |
| 1852 | static create = (params?: RawCreateParams & { coerce?: boolean }): ZodBoolean => { |
| 1853 | return new ZodBoolean({ |
| 1854 | typeName: ZodFirstPartyTypeKind.ZodBoolean, |
| 1855 | coerce: params?.coerce || false, |
| 1856 | ...processCreateParams(params), |
| 1857 | }); |
| 1858 | }; |
| 1859 | } |
| 1860 | |
| 1861 | /////////////////////////////////////// |
| 1862 | /////////////////////////////////////// |
nothing calls this directly
no test coverage detected