Can't use underlying type of string inside map of string: "cannot use <xxx> (type <yyy>) as type string in map index"

E235 :

I have underlying type of string: type Capability string.

I wanted to use it as a string inside map of strings but I am getting an error:

cannot use cap (type Capability) as type string in map index

This is my code:

package main

import (
    "fmt"
)


type Capability string
var caps_list = map[string]int {
    "HOME" : 1,
}

func main() {

    var cap Capability // string
    cap = "HOME"
    fmt.Print(string(caps_list[cap]))
}  

Why it doesn't accept it ? it is a string after all.

You can try my code here:
https://play.golang.org/p/r-h9Hu8_eoM

E235 :

Just need to change to use string on the cap:

fmt.Print(string(caps_list[string(cap)]))  

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Can't use rstrip() inside f-string python

Can not put a T in Map<String, ? extends T>

Can this type of golang string slicing leak memory in underlying byte array?

can't use emmeans inside map

Less: Can't use Map inside each

Flutter Dart - the argument type 'String' can't be assigned to the parameter type 'Map<String,dynamic>'

Flutter-Firestore "The argument type 'Map<String, dynamic> Function()' can't be assigned to the parameter type 'Map<String, dynamic>"

The argument type 'Set<String>' can't be assigned to the parameter type 'Map<String, dynamic>'

Can't use String#trim as a callback for Array#map

JSON Serialization Issue: The argument type 'Tracks' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'Map<String, dynamic> Function()' can't be assigned to the parameter type 'Map<String, dynamic>'

Flutter : Facing an error like - The argument type 'Map<String, dynamic>?' can't be assigned to the parameter type 'Map<String, Object?>'

Flutter - A value of type 'List<Map<String, Object>>' can't be assigned to a variable of type 'List<Classes>'

The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'Map<String, Object>' can't be assigned to the parameter type 'String'.dartargument_type_not_assignable

A value of type 'Set<String?>' can't be assigned to a variable of type 'Map<String, String>'

Flutter: The argument type 'HomePage Function(BuildContext, Map<String, dynamic>)' can't be assigned to the parameter type

error: The argument type 'Null' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'Map<String, dynamic>'. error showing in flutter

The argument type Set<Map<String, Widget Function(BuildContext)>> can't be assigned to the parameter type 'Map<String, Widget Function(BuildContext)>

The argument type 'Iterable<Map<String, dynamic>>' can't be assigned to the parameter type 'List<Map<String, dynamic>>'

when i trying to use API this appeared The argument type 'String?' can't be assigned to the parameter type 'String'

The argument type 'Object' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'Future<String>' can't be assigned to the parameter type 'String'. How can ı use the await?

the argument type object cann't be assigned to parameter like string in flutter while accessing the map inside the list

error using riverpod to The argument type 'String' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'CollectionReference<Object?>' can't be assigned to the parameter type 'Query<Map<String, dynamic>>'. (Documentation)

Why MyBatis can't map the JSONB type to a Map<String, Object> or to JsonNode?

Expression of type 'string' can't be used to index type - when trying to use a string as an index in an object