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

Index signature schema key type with union of literals not evaluated #1804

Open
diefans opened this issue Jan 2, 2025 · 0 comments · May be fixed by #1808
Open

Index signature schema key type with union of literals not evaluated #1804

diefans opened this issue Jan 2, 2025 · 0 comments · May be fixed by #1808
Assignees
Labels
bug Something isn't working resolver
Milestone

Comments

@diefans
Copy link

diefans commented Jan 2, 2025

Bug Report

I want to constrain the keys of an index schema against a type alias (union with literals). Using this type for values works as expected, but using this type to constrain the key of index signature schemas does not work.

I know that I can create a "check" in the schema to validate against a set of strings, but then the question arises, how to constrain the check against the type _foo without duplicating the definition of _foo.

I also played with other types for the key e.g. int and kcl throws an error ("invalid index signature key type: 'int'"), which suggests that only strings are allowed, but that would make specifying a type for the key obsolete at all...

1. Minimal reproduce step (Required)

type _foo = "foo" | "bar"

schema IndexSignature:
    [..._foo]: any

IndexSignature {
    foo = "foo"
    # this should throw an error
    baz: "baz"
}

2. What did you expect to see? (Required)

something like ^ expected str(foo) | str(bar), got str(baz)

3. What did you see instead (Required)

foo: foo
baz: baz

4. What is your KCL components version? (Required)

0.11.0-linux-amd64

@Peefy Peefy added the bug Something isn't working label Jan 2, 2025
@Peefy Peefy added this to the v1.0 Release milestone Jan 2, 2025
@Peefy Peefy assigned He1pa and Peefy and unassigned He1pa and zong-zhe Jan 2, 2025
@Peefy Peefy removed the evaluator label Jan 4, 2025
@Peefy Peefy linked a pull request Jan 4, 2025 that will close this issue
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolver
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants