kcl-lang / kcl-lang.io

KCL Website and Documentation Repo: https://kcl-lang.io
https://kcl-lang.github.io
Apache License 2.0
13 stars 35 forks source link

[FAQ] Any in dict, allow using any type #417

Open steeling opened 2 months ago

steeling commented 2 months ago

When dealing with a dict of type {str:Any}, we can't set values to {'key': 'value'} because 'value' is of type str which fails type assertions.

Would be a nice to have to allow duck typing on Any

Peefy commented 2 months ago

Sorry, do you mean the any type or the Any type?

config1: {str:any} = {'key1': 'value', 'key2': 1}
config2: {str:} = {'key': 'value'} # We can omit the any in the type annotation.