Encountered a weird problem in Godot. Consider the following code:

class_name VoiceBanks
 
const banks: Dictionary = {
		"lemon": preload("res://prefabs/voice_player/voices/ava.tres")
	}
 
static func lookup(key: String) -> VoiceBank:
	if banks.has(key):
		return banks[key]
	else:
		return null

lookup, even though it successfully finds the right VoiceBank resource, fails with the error Trying to return value of type "Resource" from a function which the return type is "VoiceBank".

However, delaying the load until later works:

class_name VoiceBanks
 
const banks: Dictionary = {
		"lemon": "res://prefabs/voice_player/banks/ava.tres"
	}
 
static func lookup(key: String) -> VoiceBank:
	if banks.has(key):
		return load(banks[key])
	else:
		return null

I’m not really sure why this is, but I’m guessing it has something to do with how Godot treats const values.