So, I think my typescrpt linter is short circuiting because, I cant for the life of me figure out why this linting error keeps being raised.
Type 'IConnectionState' is not assignable to type '{ connected: false; type: "none"; }'
Below is my code, which you can clearly see, should have no consequence.
export interface IConnectionState {
connected: boolean;
type: 'none' | 'player' | 'host';
}
export const ConnectionState: RecoilState<IConnectionState> = atom({
key: 'connectionState',
default: {
connected: false,
type: 'none'
}
});
If it helps, I'm using recoil. But looking at the recoil types, RecoilState
should type takes a subtype of the default
value given to its options object.
I'm so lost.
Actually the linter is working as expected. You are setting the type of
ConnectionState
to beIConnectionState
but you never include the propertykey
in the interface.Interface
IConnectionState
is correct but it should be nested within another Interface.If
IConnectionState
has morekey
values to it then just do the same as I did withTType
where you form a union over the possible types thatkey
can exist as.