Skip to content

Reorganize React definitions - #5579

Merged
johnnyreilly merged 4 commits into
DefinitelyTyped:masterfrom
jbrantly:react-reorg
Sep 8, 2015
Merged

johnnyreilly merged 4 commits into
DefinitelyTyped:masterfrom
jbrantly:react-reorg

Conversation

@jbrantly

Copy link
Copy Markdown
Contributor

This is a first pass at implementing #5221. This cuts the number of files from 4 to 2 and reduces the "duplicate" definitions from 3 to 2 (both in the same file, react.d.ts).

The number of duplicate definitions can be further reduced once React v0.14 is released.

cc @vsiao @pspeter3 @RyanCavanaugh

@jbrantly

Copy link
Copy Markdown
Contributor Author

This PR was originally meant to not make any real changes to the current functionality (no bugfixes, additions, etc). However, there is one issue that came up which I think we should try to go ahead and bandaid.

In fb0b124 an indexer was added to CSSProperties. I believe this was to fix the new strict object literal checking in TS 1.6 which has been causing a lot of PRs lately for missing CSS properties. It did, however, have a side effect of no longer allowing something like this:

var style = { whatever: '' };
<div style={style} />

The above will throw Index signature is missing. Note that <div style={{ whatever: '' }} /> works fine.

Changing the indexer from string | number | boolean to any fixes this problem in TS 1.6. However, TS 1.5 is still affected and the workaround is what is used in the tests:

var style: React.CSSProperties = { whatever: '' };

In any case, I've updated this PR to change the indexer to any which at least fixes TS 1.6.

@RyanCavanaugh

Copy link
Copy Markdown
Member

Just to clarify the indexer thing: another new behavior in 1.6 is that an indexer of type any does not require an indexer on the source type in order to be assignable. In other words:

let x = { whatever : '' };
let y: { [s: string]: any };
y = x; // OK in 1.6, error in 1.5

@pspeter3

pspeter3 commented Sep 1, 2015

Copy link
Copy Markdown
Contributor

Out of curiosity, what is the difference between module and namespace? I'm excited to have fewer files.

@jbrantly

jbrantly commented Sep 1, 2015

Copy link
Copy Markdown
Contributor Author

@pspeter3 It's part of the "internal modules => namespaces, external modules => modules" renaming. namespace takes the place of module for namespaces (and only namespaces). However, for backward compatibility module still works for both namespaces and modules.

In other words:

declare namespace Foo { } // works, namespace
declare namespace "Foo" { } // doesn't work
declare module Foo { } // works, namespace
declare module "Foo" { } // works, module

@pspeter3

pspeter3 commented Sep 1, 2015

Copy link
Copy Markdown
Contributor

That's awesome and makes the distinction clearer.

@vvakame

vvakame commented Sep 2, 2015

Copy link
Copy Markdown
Member

um? can I merge this PR?

@pspeter3

pspeter3 commented Sep 2, 2015

Copy link
Copy Markdown
Contributor

I feel favorably to it

@vvakame

vvakame commented Sep 2, 2015

Copy link
Copy Markdown
Member

👍
@vsiao @RyanCavanaugh Is the same opinion?

Originally had renamed react-global.d.ts to react-namespace.d.ts. After thinking about it further I don't think a rename really benefits anyone and would just cause confusion with people trying to upgrade. Also I had missed the `.d` in the original rename. Additionally adding some tests for the global version since there were none.
@jbrantly

jbrantly commented Sep 4, 2015

Copy link
Copy Markdown
Contributor Author

I just made some (I think non-controversial) changes.

  1. Renamed react-namespace back to react-global.d.ts as it originally was. No real point in changing the name and would just cause issues with people upgrading. Also I messed up the original rename and forgot the .d. Whoops.
  2. Added some tests for the global version. Basically just a copy-paste of react-tests.ts but removing the import statement.

@johnnyreilly

Copy link
Copy Markdown
Member

If @vsiao @RyanCavanaugh have no objections shall we look to merge?

johnnyreilly added a commit that referenced this pull request Sep 8, 2015
@johnnyreilly
johnnyreilly merged commit 9c76211 into DefinitelyTyped:master Sep 8, 2015
@johnnyreilly

Copy link
Copy Markdown
Member

Merged. Thanks for your work @jbrantly

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.

6 participants