Convert process-config-entities to TypeScript#2113
Convert process-config-entities to TypeScript#2113balloob merged 5 commits intohome-assistant:devfrom
Conversation
| import { EntityConfig } from "../entity-rows/types"; | ||
|
|
||
| export default function processConfigEntities(entities) { | ||
| export const processConfigEntities = (entities: EntityConfig[]) => { |
There was a problem hiding this comment.
This is not correct. The output is EntityConfig[], the input can also be a string (as tested for on line 19) so should be Array<EntityConfig | string>. Also please mark the return type
There was a problem hiding this comment.
I think that it should be something like this:
| export const processConfigEntities = (entities: EntityConfig[]) => { | |
| export const processConfigEntities = <T extends EntityConfig>(entities: Array<EntityConfig | string>[]): T[] => { |
| public setConfig(config: Config): void { | ||
| this._config = { theme: "default", ...config }; | ||
| const entities = processConfigEntities(config.entities); | ||
| const entities = processConfigEntities(config.entities) as ConfigEntity[]; |
There was a problem hiding this comment.
We should have processConfigEntities take a type that you expect return values to be.
(also, ConfigEntity and EntityConfig, we must really hate our future selves picking such confusing names)
There was a problem hiding this comment.
| const entities = processConfigEntities(config.entities) as ConfigEntity[]; | |
| const entities = processConfigEntities<ConfigEntity>(config.entities); |
There was a problem hiding this comment.
Yeah, reworking types for cards is on my todo list
|
@balloob do you have any guidance on getting past my errors, by chance? Thanks. |
|
Doesn't this work? return entities.map((entityConf, index): T[] => { |
Still a typing error which seems like it shouldn't exist
|
I believe this is related: palantir/tslint#4239 |

No description provided.