Closed janizde closed 4 years ago
This looks like a very useful PR and I would definitely use the TypeScript typings if they were available.
@balazsbotond The types are merged into DefinitelyTyped meanwhile, since there's no progess here. https://github.com/DefinitelyTyped/DefinitelyTyped/pull/45223
You can get it as @types/quicksettings
Closing this since they're available on DefinitelyTyped now https://www.npmjs.com/package/@types/quicksettings
This PR introduces TypeScript typings as a separate
index.d.ts
definition file within the module. Alternatively typings can be provided through https://github.com/DefinitelyTyped/DefinitelyTypedStructure
quicksettings
module are defined intypes/index.d.ts
types
property in the package.json points TypeScript to where to find thistypes/index.test-d.ts
and can be run with thelint
script from package.json. When all tests pass this script should exit with 0Typing Model
By default
QuickSettingsPanel
is typed in a very permissive way and does not validate control names etc. when not explicitly providing a model. In this mode the typings make sure that, e.g.setSize
,setPosition
etc are called with the correct parameters and typesaddText
are correct (i.e., the value is a string and the change handler receives a string)Example
When passing
QuickSettings.create<M, S>
generic parameters the type checking can be made more restrictive by providing the type of a model representing the options object. This also makes sure thataddText
,bindText
etc. that exist on the model typeaddText
is not registered for a key of a number)Example
For controls that do not attach to the model, like buttons or elements, the second generic argument can be passed a literal type describing the keys of such controls (this is completely optional and mostly for the sake of completeness):
Example
More examples can be found in the tests.
I'm happy to discuss the typings model and open to changes