Do these two initializations differ in functionality?
The following code snippet works as expected:
private screensMap: Map<string, ComponentType<any>>;
public constructor() {
this.screensMap = new Map()
.set(BootstrapLaunch.name, BootstrapLaunch)
.set(BootstrapWelcome.name, BootstrapWelcome);
}
However, the following code snippet encounters an error:
private screensMap: Map<string, ComponentType<any>>;
public constructor() {
this.screensMap = new Map([
[BootstrapLaunch.name, BootstrapLaunch],
[BootstrapWelcome.name, BootstrapWelcome],
]);
}
This results in the following error message:
error TS2345: Argument of type '([string, typeof BootstrapLaunch] | [string, typeof BootstrapWelcome])[]' is not assignable to parameter of type 'ReadonlyArray<[string, typeof BootstrapLaunch]>'.
Type '[string, typeof BootstrapLaunch] | [string, typeof BootstrapWelcome]' is not assignable to type '[string, typeof BootstrapLaunch]'.
Type '[string, typeof BootstrapWelcome]' is not assignable to type '[string, typeof BootstrapLaunch]'.
Type 'typeof BootstrapWelcome' is not assignable to type 'typeof BootstrapLaunch'.
Type 'BootstrapWelcome' is not assignable to type 'BootstrapLaunch'.
Types of property 'componentDidMount' are incompatible.
Type '(() => void) | undefined' is not assignable to type '() => void'.
Type 'undefined' is not assignable to type '() => void'.
Is this caused by a Typescript bug or is there something wrong with my implementation?