You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 to Text in the sanitize function (here: sanitize.ts#L31). I’d love to use String 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:
import{WsProvider,ApiPromise}from'@polkadot/api';constprovider=newWsProvider('wss://polkadot-rpc.dwellir.com');asyncfunctionmain(){constapi=awaitApiPromise.create({
provider,noInitWarn: true,types: {FieldType: {_enum: ['Uint8','Int8','String'],},},});// This line throws the error :(constfieldTypeEnum=api.createType('FieldType','String');}main().catch(console.error);
Error: createType(FieldType):: Cannot map Enum JSON, unable to find 'String' in uint8, int8, text
at createTypeUnsafe (/home/projects/node-ukhved/node_modules/@polkadot/types-create/cjs/create/type.js:54:22)
at TypeRegistry.createType (/home/projects/node-ukhved/node_modules/@polkadot/types/cjs/create/registry.js:224:52)
at ApiPromise.createType (/home/projects/node-ukhved/node_modules/@polkadot/api/cjs/base/Decorate.js:125:42)
at main (/home/projects/node-ukhved/index.ts:2:469)
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:
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. constfieldTypeEnum=api.createType("FieldType",String);console.log(fieldTypeEnum.toRawType());
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: