你好,我对 React 相当陌生,但我选择使用 typescript(我也是新手)而不是原始 JS。话虽如此,我在向react-map-gl 元素添加图层时遇到了麻烦。这是我收到的错误代码
Type '{ id: string; type: string; paint: { 'sky-type': string; 'sky-atmosphere-sun': number[]; 'sky-atmosphere-sun-intensity': number; }; }' is not assignable to type 'LayerProps'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"symbol" | "sky" | "circle" | "line" | "fill" | "fill-extrusion" | "raster" | "background" | "heatmap" | "hillshade"'.ts(2322)
Run Code Online (Sandbox Code Playgroud)
看起来像是它说它想要一个枚举?以下是代码片段:
const skyLayer = {
id: 'sky',
type: 'sky',
paint: {
'sky-type': 'atmosphere',
'sky-atmosphere-sun': [0.0, 0.0],
'sky-atmosphere-sun-intensity': 15
}
}; …Run Code Online (Sandbox Code Playgroud)