I seem to be facing a challenge related to narrowing, specifically the differentiation between Fnc (callable) and Class (newable).
The code snippet provided functions in Playground, but the autocomplete feature is lacking, as shown in the first image.
My query is how can I ensure accurate autocompletion for the Login action
, for instance?
Could this issue stem from a Fnc vs Class narrowing problem or is there another underlying cause?
Please assist me, thank you sincerely in advance.
type Fnc = (...args: any[]) => any
type Class = { new(...args: readonly unknown[]): unknown }
type Interface<C extends Class> = InstanceType<C>
declare function Test<F extends Fnc> (type: "Precondition", f:F, params:Parameters<F>[0]): typeof Test
declare function Test<C extends Class> (type: "Actor" | "System", c:C, members:Partial<Interface<C>>): typeof Test
declare const Browser: (params: {"Address": "https://sys.tem" | "http://test-env.sys.tem"}) => void
declare class Login {
"User": string
"Password": string
"action": "Sign in" | "Register" | "Request password"
"Message": "Invalid credentials" | "Credentials are required"
}
Test
("Precondition", Browser, {"Address": "https://sys.tem"})
("Actor", Login, {"User": "KO", "Password": "invalid", "action": "Sign in"})
// ^_ POOR AUTOCOMPLETION HERE ?
("System", Login, {"Message": "Invalid credentials"}
autocomplete deficiency:
https://i.stack.imgur.com/VCund.png
RESEARCH:
By making the implementation changes as follows ...
... the autocomplete works flawlessly - but the reason behind this improvement eludes me?