"does not name a type" error when I have multiple *.ino files and ALL of the code is moved into one

The process you describe is not everything that happens, I think the IDE is also generating stubs and trying to be clever when merging everything...

But it's probably trying too hard to be clever and fails including the proper definitions before using them

I'm pretty sure that if you were to keep the main part of the sketch in the main .ino file, such as:

#include <ESP8266WiFi.h>
#include <Ticker.h>
#include <AsyncMqttClient.h>

#define WIFI_SSID "My_Wi-Fi"
#define WIFI_PASSWORD "my-awesome-password"

#define MQTT_HOST IPAddress(192, 168, 1, 10)
#define MQTT_PORT 1883

AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;

WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
Ticker wifiReconnectTimer;

void setup() {
  Serial.begin(115200);
  Serial.println();
  Serial.println();

  wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
  wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);

  mqttClient.onConnect(onMqttConnect);
  mqttClient.onDisconnect(onMqttDisconnect);
  mqttClient.onSubscribe(onMqttSubscribe);
  mqttClient.onUnsubscribe(onMqttUnsubscribe);
  mqttClient.onMessage(onMqttMessage);
  mqttClient.onPublish(onMqttPublish);
  mqttClient.setServer(MQTT_HOST, MQTT_PORT);

  connectToWifi();
}

void loop() {}

and move all the functions in a secondary .ino file then everything will work (that would correspond to the expected simple view of code structure the IDE seems to expect)


My view is to not rely on multiple .ino to structure code, use .h, .hpp or .cpp files and rely (as much as possible) on standard compilation rules (ie declare something before using it etc)