Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //global.d.ts
- type ConfigMeta = StringConfig | NumberConfig
- declare interface Config<T> {
- name: string
- value: T
- }
- interface StringConfig extends Config<String> {
- type: "string"
- }
- interface NumberConfig extends Config<Number> {
- type: "number"
- }
- interface MetaData {
- name: string,
- config: ConfigMeta[]
- }
- declare function registerPlugin(meta: MetaData, callback: (config: Record<string, any>) => void): void
- //script.ts
- registerPlugin({
- name: "some plugin",
- config: [{
- type: "string",
- name: "foo",
- value: "asdf"
- }, {
- type: "number",
- name: "bar",
- value: 123
- }]
- }, (config) => {
- //the issue here, config is declared as Record<string, any>
- //however is it possible to extract type information from above config input
- //and get the correct key and associated types directly assigned?
- console.log(config) //gives { foo: "asdf", bar: 123 }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement