Comments (12)
ill try to fix this issue please
from zod.
from zod.
thanks for explaining let me fix it
it would be appreciated if i were assigned in this task
from zod.
@JacobWeisenburger I'm not sure I follow, what's your point here?
It seems you've disabled exactOptionalPropertyTypes
in your screenshot, hence the compiler adds undefined
, but other than that I don't see what you're getting at :/
from zod.
Here's my tsconfig.json
. It doesn't have exactOptionalPropertyTypes
specified.
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"module": "esnext",
"target": "esnext",
"moduleResolution": "bundler",
"moduleDetection": "force",
"allowImportingTsExtensions": true,
"noEmit": true,
"composite": true,
"strict": true,
"downlevelIteration": true,
"skipLibCheck": true,
"jsx": "preserve",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"types": [
"bun-types"
]
},
"include": [
"src/**/*",
"package.json"
]
}
from zod.
yeah? The default is false
; that doesn't make it any more correct for zod to take away the decision from the compiler for those that have it set to true
.
Imho this isn't an enhancement but a bug - zod "deliberately" add's implicit nullability even if that nullability is explicitly forbidden. From what I'm reading from other issues in this repo I'm fairly certain that this is not what zod wanted or intended.
fyi: @types/bun
exists by now, just in case.
from zod.
i understood the problem and i also looked after the source code and understood what's wrong
let me try to fix it
from zod.
from zod.
sorry im just a beginner.
from zod.
the more I look at this, the more it looks like this won't be possible without a breaking change. While I did get correct optional inference working (basically just switch addQuestionMarks
and baseObjectOutputType
and infer Required Key with extends ZodOptional
) the core of the problem is that ZodOptional adds |undefined
to its in and output.
Removing that assumption breaks other tests because optional can't depend on its wrapping context.
E.g. here
const stringSchema = z.string().optional();
const objectSchema = z.object({
foo: stringSchema
});
type S = z.infer<typeof stringSchema> // expectation: string | undefined
type O = z.infer<typeof objectSchema> // expectation: { foo?: string }
Since the stringschema can't know when it's being used in an object context it's impossible to correctly represent optional keys without also making the value "undefinedable".
Imho the only true solution (and maybe even the right one) would be to strictly reserve .optional()
for usage within objects and to have a new operation like .nullable()
, e.g. .orUndefined()
for everything else.
@colinhacks , sorry for directly mentioning you but do you see any other solution?
from zod.
🔥 I also tried but it didn't seem to make any sense to me 👎🏻
from zod.
Related Issues (20)
- How to remove errors when input changed? HOT 1
- I am getting "Invalid email" error with my company brand email address `<my name>@namespactit.com`. HOT 1
- make a new string-specific validations isLowerCase & isUpperCase HOT 3
- I am working on a PHP library heavly inspired by zod.
- "Intersection results could not be merged" does not mention the cause HOT 1
- Discriminated Union inside Discriminated Union HOT 1
- z.string().url() validates invalid urls HOT 3
- Question: Type flow in a generic validator function HOT 1
- Why is positive and negative functions uses zero as the minimum and maximum value? HOT 2
- Proposal: Create a new schema with the types based on the describe value HOT 1
- "Intersection results could not be merged" does not mention the cause HOT 2
- Bug: `z.record( z.any() )` filtering out `undefined` values
- How does it add ? in keys HOT 2
- Is there a way to validate password and passwordConfirmation onChange, before other validations have passed? HOT 2
- safeParse throws if catch throws HOT 6
- Documentation broken link HOT 6
- Is there a way to have z.coerce.number() not nullable? HOT 2
- Officially support non-string error messages HOT 2
- Dynamic error massage HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zod.