K
Kysely12mo ago
mike

aliases vs strict mode in tsconfig

I have a problem with tsconfig. When I have strict mode kysely does not find aliases. What is the "most safe strict" mode which still works with kysely?
Solution:
This is "not as intended" usage. Our internals treat keys defined in DB as a whole and when trying to figure out if an alias was used we compare against ${T} as {string}.
Jump to solution
23 Replies
koskimas
koskimas12mo ago
What do you mean by "not finding aliases"? strict: true should be enough Could you create a simple reproduction using https://kyse.link
mike
mike12mo ago
mike
mike12mo ago
I'll do it - meanwhile some screenshots
koskimas
koskimas12mo ago
What's the error there? Are you sure the validFrom column exists there?
mike
mike12mo ago
Argument of type '"latest.validFrom"' is not assignable to parameter of type 'ReferenceExpression<Database & { Article: { { ...; }, "Article" | "latest">'. and yes, when strict false I receive full list of the alias "latest" from the original Article type
mike
mike12mo ago
without the "as alias" it works as expected
mike
mike12mo ago
my tsconfig setup: { "extends": "../../../../tsconfig.base.json", "files": [], "include": [], "references": [ { "path": "./tsconfig.lib.json" }, { "path": "./tsconfig.spec.json" } ], "compilerOptions": { "forceConsistentCasingInFileNames": true, "strict": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true } }
koskimas
koskimas12mo ago
Ok, I'm guessing the type of the validFrom variable is wrong What is it and what's the type of the validFrom column in the table interface?
mike
mike12mo ago
it's Date
koskimas
koskimas12mo ago
Both are Date?
mike
mike12mo ago
and the value is:
koskimas
koskimas12mo ago
I think I'll need a reproduction. That works just fine in our tests.
mike
mike12mo ago
It's hard to reproduce with the kyse.link as there is no tsconfig available imho can you send me your tsconfig? we use NX monorepo so the tsconfigs are inherited from multiple layers so it's not so easy to reproduce in a simple way
koskimas
koskimas12mo ago
"compilerOptions": {
"moduleResolution": "Node",
"target": "ESNext",
"declaration": true,
"strict": true,
"noImplicitAny": true
}
"compilerOptions": {
"moduleResolution": "Node",
"target": "ESNext",
"declaration": true,
"strict": true,
"noImplicitAny": true
}
mike
mike12mo ago
nope
koskimas
koskimas12mo ago
Well then I can't help you
mike
mike12mo ago
I know - typescript is sometimes frustrating. I'll do some investigation. currently writing script which generates all the tsconfig set values (including those extended) and maybe I'll find something I've finally found it. it wasn't tsconfig but it is somehow linked with https://discord.com/channels/890118421587578920/1123870829801918465/1123945699600519188 as I was trying to hack the aliases by extra object referencing the interface but probably made some mistake. I'll make it working and than ask for a help if needed Ok, I have reproduction. I tried to hack by adding default "as alias" key in the db interface however it doesn't work as expected. Can you imagine to make this working even with the plugin? https://kyse.link/?p=s&i=IZtt7NB4jNWJmyFVj3yJ
Solution
Igal
Igal12mo ago
This is "not as intended" usage. Our internals treat keys defined in DB as a whole and when trying to figure out if an alias was used we compare against ${T} as {string}.
mike
mike12mo ago
ok, good to know I still stuggle with the strict mode. can anybody check for me following configuration?
{
"compileOnSave": false,
"compilerOptions": {
"rootDir": ".",
"sourceMap": true,
"declaration": true,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"checkJs": true,
"experimentalDecorators": true,
"importHelpers": true,
"esModuleInterop": true,
"target": "es2015",
"module": "esnext",
"lib": ["es2017","dom"],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"noImplicitThis": true,
"baseUrl": ".",
"downlevelIteration": false,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"outDir": "../../../../dist/out-tsc",
"strict": true,
"types": [],
},
"exclude": ["jest.config.ts","src*.spec.ts"],
"files": [],
"include": ["src*.ts"],
}
{
"compileOnSave": false,
"compilerOptions": {
"rootDir": ".",
"sourceMap": true,
"declaration": true,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"checkJs": true,
"experimentalDecorators": true,
"importHelpers": true,
"esModuleInterop": true,
"target": "es2015",
"module": "esnext",
"lib": ["es2017","dom"],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"noImplicitThis": true,
"baseUrl": ".",
"downlevelIteration": false,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"outDir": "../../../../dist/out-tsc",
"strict": true,
"types": [],
},
"exclude": ["jest.config.ts","src*.spec.ts"],
"files": [],
"include": ["src*.ts"],
}
sorry - of course with strict: true
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
mike
mike12mo ago
no idea, any link?
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
mike
mike12mo ago
oh, I see. we generate our libraries via nx but it should be up-to-date for sure