-
Notifications
You must be signed in to change notification settings - Fork 365
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
Unable to Use String
as Enum Key - Auto-Converts to Text
#6117
Comments
Ah, I see what's your issue, the type being inferred isn’t actually wrong. The problem is with how the value is being passed in the line that’s throwing the error. You’ll want to do it like this instead: // The String type is passed as a type WITHOUT quotes.
const fieldTypeEnum = api.createType("FieldType", String);
console.log(fieldTypeEnum.toRawType()); The output will then be {"_enum":{"Uint8":0,"Int8":1,"Text":2}} LMK if that solves your issue 😄 |
I'm sorry for the confusion. I need the enum key to be a |
Can you provide more context as to why this is causing issues🙏🏻. AFAIK the |
I understand your point, but I need to know how to use a |
The reason you can’t use We could definitely add some comments or docs to make this clearer. That said, |
Yes, I need the enum key to literally be |
Since this behavior is intentional and part of how the API aligns with Substrate types, I’ll go ahead and close the issue. If you run into a concrete issue where this impacts functionality beyond naming, feel free to reopen or open a new issue with more details. |
Hi Polkadot-JS team! I’m running into a small hiccup and could use your help. When I try to define an enum with
String
as a key, it seems to get auto-converted toText
in the sanitize function (here: sanitize.ts#L31). I’d love to useString
directly, but I’m not sure if I’m missing something!Current Behavior:
Defining an enum with
String
throws an error:Error: createType(FieldType):: Cannot map Enum JSON, unable to find 'String' in uint8, int8, text
.Expected Behavior:
I’d hope to use
String
(or any custom key) in my enum without conversion. If that’s not possible, maybe a quick note in the docs could save folks like me some head-scratching? 😊Steps to Reproduce:
Here’s a simple snippet:
You can also play with it here: StackBlitz Link.
The script is throwing an error.
Thoughts:
Am I approaching this wrong? Any guidance would be super appreciated—thanks so much for all the amazing work you do! 🙏
The text was updated successfully, but these errors were encountered: