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:Jump to 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}
.23 Replies
What do you mean by "not finding aliases"?
strict: true
should be enough
Could you create a simple reproduction using https://kyse.linkI'll do it - meanwhile some screenshots
What's the error there? Are you sure the
validFrom
column exists there?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
without the "as alias" it works as expected
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
}
}
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?it's Date
Both are
Date
?and the value is:
I think I'll need a reproduction. That works just fine in our tests.
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
nope
Well then I can't help you
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
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}
.ok, good to know
I still stuggle with the strict mode. can anybody check for me following configuration?
sorry - of course with strict: true
you could use an pinionated config. there's a liibrary for that
opinionated*
I use it in all my libraries
no idea, any link?
oh, I see. we generate our libraries via nx
but it should be up-to-date for sure