Skip to content

Conversation

@netochaves
Copy link
Contributor

Summary:

Part of #683
Converted commands/config to typescript

Test Plan:

Green CI

import {Config} from '@react-native-community/cli-types';

function isValidRNDependency(config) {
function isValidRNDependency(config: any) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this config can be typed as:

config: AndroidDependencyConfig | IOSDependencyConfig | null

Copy link
Contributor Author

@netochaves netochaves Sep 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having trouble to set the type of this parameter, I've tried this approach but it isn't working

name: 'config',
description: 'Print CLI configuration',
func: async (argv: string[], ctx: ConfigT) => {
func: async (ctx: Config) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to the first argument of the function? Have you made sure everything works as expected with this change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config is a second argument. This change breaks that. If argv is not used, prepend it with an underscore: _argv

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I din't notice that, I'll fix it.

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for the PR! Please implement the feedback from @Esemesek and rebase to latest master to resolve conflicts :)

@netochaves netochaves force-pushed the configMigrate branch 2 times, most recently from a454ad8 to 10eb772 Compare September 10, 2019 19:37
thymikee
thymikee previously approved these changes Sep 10, 2019
@thymikee
Copy link
Member

Looks like TS is failing


function isValidRNDependency(config) {
function isValidRNDependency(
config: AndroidDependencyConfig | IOSDependencyConfig | null,
Copy link
Contributor

@assuncaocharles assuncaocharles Sep 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea, but maybe we want to the Dependency in @react-native-community/cli-types as an interface like:

export interface Dependency {
  [key: string]: {
    name: string;
    root: string;
    platforms: {
      android?: AndroidDependencyConfig | null;
      ios?: IOSDependencyConfig | null;
      [key: string]: any;
    };
    assets: string[];
    hooks: {
      prelink?: string;
      postlink?: string;
    };
    params: InquirerPrompt[];
  };
}

Don't forgetting to update the Config interface to dependencies: {[key:string] Dependacy }; and here we can use:

import {
  Dependency
} from '@react-native-community/cli-types';

function isValidRNDependency(
  config: Dependency
) {
  return (
    Object.keys(config.platforms).filter(key => Boolean(config.platforms[key]))
      .length !== 0 ||
    (config.hooks && Object.keys(config.hooks).length !== 0) ||
    (config.assets && config.assets.length !== 0) ||
    (config.params && config.params.length !== 0)
  );
}

It would solve most of the problems breaking in this file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, makes sense to extract this. We used this type in Flow files:

cli/types/index.js

Lines 172 to 175 in fde227d

export type DependencyConfigT = $PropertyType<
$PropertyType<ConfigT, 'dependencies'>,
'[key: string]',
>;

@Esemesek can you take it over?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Esemesek is working on this? if not I would like to.

Copy link
Member

@thymikee thymikee Sep 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@netochaves sure, please do!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should i create a new pr for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, do it here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@thymikee thymikee dismissed their stale review September 12, 2019 22:16

CI breaking

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@thymikee thymikee merged commit 3b6838a into react-native-community:master Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants