user defined value types allow creating a zero cost abstraction over an elementary value type. This is similar to an alias, but with stricter type requirements.
unfortunately, solc 0.8.9 says
TypeError: Unary operator delete cannot be applied to type MyType
type TokenId is uint256;
...
mapping(bytes32 => MyType) public myMapping;
...
delete myMapping[myId];
Is there a way to keep delete
for readability, use the type definition, and avoid multiple additional wrap
and unwrap
?
MyType
struct/type with your question?MyType = TokenId
, but I could be wrong.