Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

WidgetMixin#properties should not be a Partial #199

Closed
mwistrand opened this issue Jan 4, 2017 · 3 comments
Closed

WidgetMixin#properties should not be a Partial #199

mwistrand opened this issue Jan 4, 2017 · 3 comments
Milestone

Comments

@mwistrand
Copy link
Contributor

Bug

Since WidgetProperties uses an index signature, it does not play nicely with Partial. As a result, dot notation cannot be used to access concrete Widget#properties values defined in interfaces that extend WidgetProperties. This can be resolved by changing properties: Partial<P> to just properties: P within the WidgetMixin interface.

Package Version: v2.0.0-alpha.17

Code

interface CustomProperties extends WidgetProperties {
    customProperty: string;
}

const properties: Partial<CustomProperties> = {};
properties.customProperty = 'some value';

Expected behavior:

The TypeScript compiler should not throw any errors when setting customProperty via dot notation.

Actual behavior:

The TypeScript compiler throws the error: Property 'customProperty' does not exist on type 'Partial<CustomProperties>'.

@mwistrand
Copy link
Contributor Author

Resolved by #82.

@dylans dylans added this to the 2017.01 milestone Jan 9, 2017
@agubler
Copy link
Member

agubler commented Jan 10, 2017

@mwistrand I think we resolved this the wrong way round! We probably should have removed the index type from partial until 2.1.5 is released, as we want authors to be able to defined widget properties with mandatory attributes.

I have tested the scenario on the insider version of 2.1.5 and it does resolve the issue, so In the mean time we'll put back the partial but remove the index type and I'll create an issue to add the index type to both state and properties once 2.1.5 has been released.

@agubler
Copy link
Member

agubler commented Jan 10, 2017

This is a complete isolated repro of the problem in 2.1.4 that is resolved in 2.1.5

interface State {
	[index: string]: any;
	id: string;
}

const state: Partial<State> = {
	id: 'id'
};

state.id = 'next-id'; // errors in 2.1.4
state['other'] = [];

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants