Conditional returning, returning wrong types

Condtionals in returning are not returning the correct types.
No description
No description
10 Replies
rphlmr ⚡
rphlmr ⚡6mo ago
But even if I can't reproduce the undefined, I note that the return type does not keep the 'optional' part of the returning obj
lordbinbash
lordbinbashOP6mo ago
tsconfig -
{
"compilerOptions": {
"target": "ES2022",
"lib": ["dom", "dom.iterable", "ES2022"],
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"moduleDetection": "force",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"noUncheckedIndexedAccess": true,
"verbatimModuleSyntax": true,
"noImplicitOverride": true,
"plugins": [{ "name": "next" }],
"paths": { "@/*": ["./*"] }
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
".eslintrc.cjs",
"**/*.ts",
"**/*.tsx",
"**/*.cjs",
"**/*.mjs"
],
"exclude": ["node_modules", ".next"]
}
{
"compilerOptions": {
"target": "ES2022",
"lib": ["dom", "dom.iterable", "ES2022"],
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"moduleDetection": "force",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"noUncheckedIndexedAccess": true,
"verbatimModuleSyntax": true,
"noImplicitOverride": true,
"plugins": [{ "name": "next" }],
"paths": { "@/*": ["./*"] }
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
".eslintrc.cjs",
"**/*.ts",
"**/*.tsx",
"**/*.cjs",
"**/*.mjs"
],
"exclude": ["node_modules", ".next"]
}
Yeah this seems wrong
const user: {
id: number;
age: number;
}
const user: {
id: number;
age: number;
}
rphlmr ⚡
rphlmr ⚡6mo ago
The undefined inference is due to noUncheckedIndexedAccess. Without it it should be "good" You may want this option in TS, but the drawback is that now you have to check that array items are not undefined And for that I think it is a Drizzle bug because the object passed to returning is correctly infered
rphlmr ⚡
rphlmr ⚡6mo ago
(from one of my projects)
No description
lordbinbash
lordbinbashOP6mo ago
Yeah not too worried about the undefined thing, was just playing around and noticed some weird behaviour. But in the case of a conditional returning, the return type is a drizzle issue?
rphlmr ⚡
rphlmr ⚡6mo ago
for this no
No description
rphlmr ⚡
rphlmr ⚡6mo ago
but for the missing optional flag (z?: number) yes I guess I missed your 2nd screenshot sorry, I am looking at it 2nd screenshot is bug yeah. Pretty sure it is related
lordbinbash
lordbinbashOP6mo ago
I'm more just worried about the type saying something exists, when it may or may not exist 🥶
rphlmr ⚡
rphlmr ⚡6mo ago
I will return everything and forget everything you have discovered 😂 I will try to open an issue about that, thx!
Want results from more Discord servers?
Add your server