Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[#412] frint-config/Typescript #423

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

[#412] frint-config/Typescript #423

wants to merge 1 commit into from

Conversation

adrw
Copy link
Contributor

@adrw adrw commented Jun 11, 2018

Unsure how to get past the below typing error so I added rudimentary Typescript support just with any for function-returned arrays of externals.

Issue

Consider if there was a type External.

declare type External = {
  root: string|string[]|Array<string>;
  commonjs: string;
  commonjs2: string;
  amd: string;
}

From my research, there doesn't seem to be a way to define a further type that is an object of strings mapping to External.

let lodashExternal : External = {
      root: '_',
      commonjs: 'lodash',
      commonjs2: 'lodash',
      amd: 'lodash',
   }

let rxjsExternal : External = { ... }

export const thirdParties = [{
  'lodash': lodashExternal,
  'rxjs': rxjsExternal,
    ...
]

In the example above, though it is clear that the const thirdParties consists of named External objects, how can this type be defined without explicitly defining each library?

export declare type Externals = [{
  'lodash'?: External,
  'rxjs'?: External,
  'react'?: External,
  'react-dom'?: External,
  'prop-types'?: External,
  'frint'?: External,
  'frint-store'?: External,
  'frint-model'?: External,
  'frint-data'?: External,
  'frint-react'?: External,
  'frint-router'?: External,
  'frint-router-react'?: External,
...
}

@fahad19
Copy link
Member

fahad19 commented Jun 12, 2018

Thanks for the PR, @andrewparadi!

TypeScript also supports any for keys. for example, in this interface:

interface Foo {
  [key: string]: any;
}

It means, any object implementing the Foo interface can have any keys which is a string, which any value.

@fahad19
Copy link
Member

fahad19 commented Jun 12, 2018

Refs #412

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants