-
-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Labels
enhancementFeature requestFeature request
Description
Preflight Checklist
- I have read the contribution documentation for this project.
- I agree to follow the code of conduct that this project follows, as appropriate.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Problem Description
TypeScript compiler can't validate string literals for TargetArch
and TargetPlatform
types:
import { HookFunction, HookFunctionErrorCallback, OfficialArch, OfficialPlatform, TargetArch, TargetPlatform } from '@electron/packager';
// ...
const hookFunctionExample: HookFunction = (buildPath: string, electronVersion: string, platform: TargetPlatform, arch: TargetArch, callback: HookFunctionErrorCallback) => {
const something1: TargetArch = "foo" // will compile, but obviously incorrect
const something2: TargetPlatform = "Шind0wz 123" // will compile, but obviously incorrect
const something3: OfficialArch = "foo" // will not compile, but distincts from the `arch` parameter's type
const something4: OfficialPlatform = "Шind0wz 123" // will not compile, but distincts from the `platform` parameter's type
// ...
}
// ...
That's because the TypeScript compiler expands these types to any value string (source link):
// From now TargetArch and TargetPlatform are basically unconstrained string type aliases
export type TargetArch = OfficialArch | string;
export type TargetPlatform = OfficialPlatform | string;
Proposed Solution
I see several possible solutions:
- Remove
TargetArch
andTargetPlatform
in flavor ofOfficialArch
andOfficialPlatform
respectively- Or at least do it in
HookFunction
signature
- Or at least do it in
- Remove
| string
type expansion fromTargetArch
andTargetPlatform
I'm not sure what is the semantic difference between OfficialArch
and TargetArch
types so a clarification from Electron Packager devs is required to choose the best solution
Alternatives Considered
None
Additional Information
None
Metadata
Metadata
Assignees
Labels
enhancementFeature requestFeature request