Skip to main content

Mojo function

get_base_type_name

get_base_type_name[T: AnyType]() -> StaticString

Returns the name of the base type of a parameterized type.

For parameterized types like List[Int], this returns "List". For non-parameterized types, it returns the type's simple name.

Unlike get_type_name, this function strips type parameters and returns only the unqualified base type name.

Example:

from collections import List, Dict

fn main():
    print(get_base_type_name[List[Int]]())  # "List"
    print(get_base_type_name[Dict[String, Int]]())  # "Dict"
    print(get_base_type_name[Int]())  # "Int"

Parameters:

  • T (AnyType): The type to get the base name of.

Returns:

StaticString: The unqualified name of the base type as a StaticString.

Was this page helpful?