ประเภทหนัง
ตัวอย่างหนัง Solana: Anchor IDL failing to initialize in TS SDK with `Error: undefined is not an object (evaluating ‘s.split’)`
Oshibba with IDL IDL Legacy
Solana Explorer, Popular Platform for Access and Disagreeing Entertainment Blockchain, assists problems with Legacy IDL in Typescript SDK. One conquret scoop, which was affiliated, is “unpredited, is not an objection (s.split”).
This question is the question of the predatting the domain name Explorer.Solana.com in the format Camelcast, which is threw some more old IDL. The problem is concluded in the volume, how typescript is the method of
Split ()Strok in some cases.
Problem:
At the presence of the domain name in the CamelCase Typescript, the methodSplit ()with the empty buckle in the quality of the separator is asked. However, when
Explorer.solana.comdoes not exist with a heavy buckle (that is, there is no stretch),
S.Ssplit () Returizes the massive, contemporary only one element. In this case, the
undefined ‘look out of the object.
Resolution:
To solve this problem, you can use the second underweight for the prey of the domain name in the Camelcase. One of the sides will make up the use of regular expression (regex) in your Typescript code.
Here is a predicted primer, which is used by the Regex for reaching the gastrointestinal resulted:
`Typescript
Import * as TS from “Typescript”;
// Available that we have the following IDL:
Const Exploreridl =
// This is the IDL IDL.
// He has to be a pre -formation in Camelcast, as this: "Explorer.solana.com" -> "Explorer.solana.com"
;
Function Converttocamelcase (IDL: String): String {
Const Parser = Ts.CreateParser (IDL);
Const SourceFile = ts.CreatesourceFile (‘IDL.T’, IDL, TS.Scripttarget.es2015);
Empty CamelCaseidl = ”;
For (CONST TOKEN OF PARSER.GETTOKENS (SOURCEFILE) {
IF (ts.isidentifier (token) &&! token.value.startswith (‘_’)) {
Camelcastidl += Token.name;
} ELSE IF (TS.ISSSTRINGLITEL (TOKEN)) {
Const Regex = New Regexp ($ {TOKEN.VALUE.REPLACE (/([A-Z]) | ([A-Z])/G, '$ 1 $ 1')}
, ‘U’);
Let’s do it: Regexpexecarray | zero;
While ((Match = Regex.exec (Token.value))! == null) {
Camelcastidl += Match [0] [0] .tolowerCase ();
}
} ELSE IF (TS.ISEXPRESSIONSTEMENT (TOKEN)) {
CamelCaseidl += Converttocamelcast (Token.Expression);
}
}
return Camelcaseidl;
}
Console.log (Converttocamelcast (Exploreridl));
`
In this accordance with the functioning of Converttocamelcase ()
If this is an identifier, he simply adds his name to Stroke Camelcase IDL. If this is a stronger book, it will intervene the stack, the same regulation is used, and the storage adds its first letter (in the upper reagistra) to strike camelcast idl.
Conclusion:
The problem with the entrance code can be resolved with the use of regular expression in typescript for the prey of the domain name in Camelcase. This underwear guarantees that the right objects are outbuilding, and the “unpredited objection” is shot “.