Skip to content

Add @types/jss - #21851

Merged
bowdenk7 merged 2 commits into
DefinitelyTyped:masterfrom
appsforartists:jss
Dec 6, 2017
Merged

bowdenk7 merged 2 commits into
DefinitelyTyped:masterfrom
appsforartists:jss

Conversation

@appsforartists

Copy link
Copy Markdown
Contributor
  • Use a meaningful title for the pull request. Include the name of the package modified.

  • Test the change in your own code. (Compile and run.)

  • Follow the advice from the readme.

  • Avoid common mistakes.

  • Run npm run lint package-name (or tsc if no tslint.json is present).

  • The package does not provide its own types, and you can not add them.

  • If this is for an NPM package, match the name. If not, do not conflict with the name of an NPM package.

  • Create it with dts-gen --dt, not by basing it on an existing project.

  • tslint.json should be present, and tsconfig.json should have noImplicitAny, noImplicitThis, strictNullChecks, and strictFunctionTypes set to true.

@dt-bot

dt-bot commented Nov 30, 2017

Copy link
Copy Markdown
Member

types/dvtng__jss/index.d.ts

Checklist


types/jss/index.d.ts

to author (@Ptival). Could you review this PR?
👍 or 👎?

@appsforartists

Copy link
Copy Markdown
Contributor Author

cc @kof

@typescript-bot

Copy link
Copy Markdown
Contributor

@appsforartists Please fix the failures indicated in the Travis CI log.

@appsforartists

Copy link
Copy Markdown
Contributor Author

I don't understand. https://travis-ci.org/DefinitelyTyped/DefinitelyTyped/builds/309288324 says I need to rename the old tests to dvtng__jss-tests.ts, but as you can see in its linked commit, I've already done that.

@appsforartists

Copy link
Copy Markdown
Contributor Author

@kof, thanks for your comments. I deleted the internal-only types. Not sure what to do about the Rule types - I'm a bit tempted to just implement whatever the docs expose and call it good enough for now.

@kof

kof commented Nov 30, 2017

Copy link
Copy Markdown

I thinnk that would be fine,considered we didn't have any typings for ts at all.

@kof

kof commented Nov 30, 2017

Copy link
Copy Markdown

Actually I should have added flow types only to public API, that way it would be easier for everyone.

@appsforartists

Copy link
Copy Markdown
Contributor Author

Thorough types hopefully helps you catch implementation problems on your end, and might make some types more specific for downstream authors (like knowing which kind of Rule you're working with). But, it's not worth the effort or the maintenance cost for an external typing like this one - we just need the public API.

@appsforartists

Copy link
Copy Markdown
Contributor Author

@kof - I just pushed a new revision, that includes types for (nearly) everything documented at http://cssinjs.org/js-api?v=v9.3.3.

For the record, he and I had a long chat inline at appsforartists@47e2432 regarding how to handle Rule (which is a union of a bunch of types in Flow, but is documented as if it's a single type). For now, we're writing TS types that match the documentation, and may update both to be more accurate in the future.

@@ -0,0 +1,16 @@


jss.set('.demo', {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

where does this come from? doesn't look like the right interface 😄

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Oh this comes from a different project, from Box9/jss

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, somebody was squatting on @types/jss, so I had to move it before I could write these.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

foo__bar is the style for scoped packages e.g. @dvtng/jss on npm. We don't really have a style for things not published to npm; I would just call this dvtng-jss.

Comment thread types/jss/index.d.ts Outdated
/**
* Link renderable CSS rules from sheet with their corresponding models.
*/
link(): this;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I consider this one to be a private method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed. indexOf doesn't appear to be documented either, but I left it since index is.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Used in plugins only.

Comment thread types/jss/index.d.ts
onProcessRule(rule: Rule, sheet: StyleSheet<any>): void,
onProcessStyle(style: Style, rule: Rule, sheet: StyleSheet<any>): Style,
onProcessSheet(sheet: StyleSheet<any>): void,
onChangeValue(value: any, prop: string, rule: Rule): any,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is one more: onUpdate(data, rule, sheet)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@kof

kof commented Nov 30, 2017

Copy link
Copy Markdown

Ok, couldn't find anything else.

@kof

kof commented Nov 30, 2017

Copy link
Copy Markdown

Yep, we added docs for it just recently, it was "internal" before, will publish soon. Also missed in flow types.

@kof

kof commented Nov 30, 2017

Copy link
Copy Markdown

@appsforartists

Copy link
Copy Markdown
Contributor Author

Ahhh - I couldn't find it in the codebase because I had 9.2 checked out. Updated.

@appsforartists

Copy link
Copy Markdown
Contributor Author

@Andy-MS Travis keeps telling me the build failed because the tests file for dvtng__jss was called jss-tests.ts, but that's been fixed since the first revision. Any idea what's causing it, or how to get it to test the current commit?

Comment thread types/jss/index.d.ts Outdated
/**
* Get a rule by name.
*/
getRule(name: keyof T | string): Rule;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

keyof T | string is just string

Comment thread types/jss/index.d.ts Outdated
* Update the function values with a new data.
*/
update(data?: {}): this;
update(name?: string, data?: {}): this;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These parameters don't need to be optional since the ability to pass 0 or 1 arguments is handled by the first overload

Comment thread types/jss/index.d.ts
* Creates a new instance of JSS.
*/
export function create(options?: Partial<JSSOptions>): JSS;
/**

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The comment says you're exporting an instance, but this exports the class.

Comment thread types/jss/jss-tests.ts Outdated
).attach();

// test that `classes` has strings for each key in the `styles` argument
styleSheet.classes.container.toUpperCase();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could use // $ExpectType string instead.

@@ -0,0 +1,16 @@


jss.set('.demo', {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

foo__bar is the style for scoped packages e.g. @dvtng/jss on npm. We don't really have a style for things not published to npm; I would just call this dvtng-jss.

@ghost

ghost commented Nov 30, 2017

Copy link
Copy Markdown

@appsforartists It gets the files list from tsconfig.json.

Fixes DefinitelyTyped#19974

The type definitions in `@types/jss` don't match the `jss` package on npm, which has nearly 400k monthly downloads.  I'm not sure where to put the definitions currently squatting at `jss`, as it [doesn't appear that](https://www.npmjs.com/~dvtng) @dvtng has published them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New Definition This PR creates a new definition package. Unmerged The author did not merge the PR when it was ready.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants