K
Kysely2y 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
koskimas2y 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
mikeOP2y ago
mike
mikeOP2y ago
I'll do it - meanwhile some screenshots
koskimas
koskimas2y ago
What's the error there? Are you sure the validFrom column exists there?
mike
mikeOP2y 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
mikeOP2y ago
without the "as alias" it works as expected
mike
mikeOP2y 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
koskimas2y 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
mikeOP2y ago
it's Date
koskimas
koskimas2y ago
Both are Date?
mike
mikeOP2y ago
and the value is:
koskimas
koskimas2y ago
I think I'll need a reproduction. That works just fine in our tests.
mike
mikeOP2y 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
koskimas2y ago
"compilerOptions": {
"moduleResolution": "Node",
"target": "ESNext",
"declaration": true,
"strict": true,
"noImplicitAny": true
}
"compilerOptions": {
"moduleResolution": "Node",
"target": "ESNext",
"declaration": true,
"strict": true,
"noImplicitAny": true
}
mike
mikeOP2y ago
nope
koskimas
koskimas2y ago
Well then I can't help you
mike
mikeOP2y 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
Igal2y 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
mikeOP2y 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
Igal (mobile)
Igal (mobile)2y ago
you could use an pinionated config. there's a liibrary for that opinionated* I use it in all my libraries
mike
mikeOP2y ago
no idea, any link?
mike
mikeOP2y ago
oh, I see. we generate our libraries via nx but it should be up-to-date for sure
Want results from more Discord servers?
Add your server