Closed joeledwardson closed 1 month ago
Answered about a billion times.
where?
I did have a look through the docs and issues before writing this and found many asking similar questions regarding type narrowing and filtering but none that match what I'm asking here.
$narrowType
which is referring to the returned typeHere's just a few I found using a the word generic
. There are A LOT more here and in discord. The gist is always the same: extremely strict (Kysely) and generics don't work well together. Strict expects exact types to be known and generic is the opposite.
https://github.com/kysely-org/kysely/issues/997 https://github.com/kysely-org/kysely/issues/995 https://github.com/kysely-org/kysely/issues/670 https://github.com/kysely-org/kysely/issues/642 https://github.com/kysely-org/kysely/issues/496 https://github.com/kysely-org/kysely/issues/385 https://github.com/kysely-org/kysely/issues/122 https://github.com/kysely-org/kysely/issues/109 https://github.com/kysely-org/kysely/issues/43
I am trying to use kysely to narrow a type in a function so I can create a generalise function that accepts string column types (see
filterString
). But typescript is not recognising thevalue
as narrowed to a string type and throwing an error.I've taken the database tables from the docs for an example.
How can I create a generic function that will allow kysely to recognise a narrowed type of a reference expression so I can call it will a string?