Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect types and missing suggestions when using object index signature #852

Closed
vladshcherbin opened this issue Jan 19, 2024 · 2 comments

Comments

@vladshcherbin
Copy link
Contributor

vladshcherbin commented Jan 19, 2024

When using object index signature, known properties get | null type and ref.key suggestions are missing. Without index signature everything is working correctly.

Example with correct ref.key suggestions and correct brand slug field type:

https://kyse.link/?p=s&i=MmozcfIdl4l3HrV97ncr

Same example without ref.key suggestions and with incorrect brand slug field type (it can't be null):

https://kyse.link/?p=s&i=PlNhdkgf4RggHGJnuqVX

kysely 0.27.2

related zod issue - #850

@koskimas
Copy link
Member

I don't think it's possible to fix that. Just try doing this

type X = keyof Brand
const x: X = 'slug'

you don't get suggestions for slug even here.

@vladshcherbin
Copy link
Contributor Author

vladshcherbin commented Jan 20, 2024

@koskimas yeah, doesn't work for me too ☹️

What about the brand.slug type from the second example link? It's string | null but from the type it can only be a string. Can this somehow be fixed or it's also not possible?

--- added ---

Managed to get it working when key is not of a string type.
Maybe typescript overrides slug definition when is set as string.

type Brand = {
  slug: string
  [key: number]: string
}

type Key = keyof Brand

const a: Key = 'slug'

Result:

image

No idea how to fix this sadly ☹️ Seems like microsoft/TypeScript#29729

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants