Here's a simplification of the question:
const TestVectorLayer = function(layerName: string) {
};
const layer = new TestVectorLayer("");
The error is happening because TestVectorLayer
doesn't have a new signature, so layer
is implicitly typed as any
. That errors with --noImplicitAny
.
You can fix this by switching to a class, but in your case this seems a bit more complicated because the inheritance is done by the underlying framework. Because of that, you will have to do something a bit more complicated and it's not ideal:
interface TestVectorLayer {
// members of your "class" go here
}
const TestVectorLayer = function (this: TestVectorLayer, layerName: string) {
// ...
console.log(layerName);
ol.layer.Image.call(this, opts);
} as any as { new (layerName: string): TestVectorLayer; };
ol.inherits(TestVectorLayer, ol.layer.Image);
export default TestVectorLayer;
Then in the file with TestComponent
:
const layer = new TestVectorLayer(layerName); // no more compile error
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…