eclipse-theia / theia

Eclipse Theia is a cloud & desktop IDE framework implemented in TypeScript.
http://theia-ide.org
Eclipse Public License 2.0
19.93k stars 2.49k forks source link

Fix type definition of `TheiaAppFactory` #13799

Closed tortmayr closed 3 months ago

tortmayr commented 3 months ago

What it does

Ensure that the TheiaAppFactory type does match the constructor function of TheiaApp. InitialWorkspace is required in the TheiaApp constructor butwas optional in TheiaAppFactory This ensures that (sub)classes of TheiaApp can properly be used as app factory without type casting

Contributed on behalf of STMicroelectronics

How to test

Using the TheiaAppLoader with a TheiApp (sub)class as factory parameter should now work and not have a ts error:

// Mock playwright args
cons args= {} as TheiaPlaywrightTestConfig & PlaywrightWorkerArgs

// Simle test 
const app= TheiaAppLoader.load({playwright,browser}, undefined, TheiaApp)

// test with subclass
class SpecialTheiaApp extends TheiaApp{
}
const app:SpecialTheiaApp= TheiaAppLoader.load({playwright,browser}, undefined, SpecialTheiaApp)

On master this would throw a compile error and a cast like `SpecialTheiaApp as TheiaAppFactory<SpecialApp>` would required

Follow-ups

Review checklist

Reminder for reviewers