-
Notifications
You must be signed in to change notification settings - Fork 61
Conversation
Hi @dannyfritz, could you please reference this PR from #5 |
Which TSLint does this correlate to? EDIT: found it in your docs 😄 |
docs/rules/no-type-literal.md
Outdated
@@ -0,0 +1,121 @@ | |||
# Enforces the use of interfaces over type literals (`type T = {...}`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeScript refers to these as "Type Aliases" in their docs, so please could we go for that name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct me if I'm wrong, isn't type aliases a much broader concept? a type alias could be:
- an actual alias
type foo = string | string[];
- a callback
type foo = () => 'hello';
- a literal
type foo = {};
I used type literals, because the rule only covers the last case...
anyway I'm ok changing the text, just want to make sure you are ok with this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Sorry not on computer right now, so can't do much digging)
We have the "allowUnion" and "allowIntersection" configuration in this rule which broadens it from just a literal, right? Plus should we not actually be including your callback example in this rule as well?
e.g. should we not be preferring func2
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this rule is based on the tslint rule (which includes only the literals), but yeah, we can broaden the scope by including the callback too. I think we should consider renaming the rule, though...
thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by the way, the allowUnion and allowIntersection enable compositions that include a literal type. e.g.
type foo = string & {};
now I'm not so sure if we still need them if we go with literals and callbacks. I think we can rename the rule to no-type-aliases, with two properties allowTypeLiterals and allowCallbacks
docs/rules/no-type-literal.md
Outdated
|
||
This rule aims to standardise the use of interfaces across the codebase. | ||
|
||
## Options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with the other PR, please can we stick to the exceptions being false
by default for "no-" rules, I feel it is much clearer to users of the rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're killing it with these PRs @weirdpattern, thank you!
Just some minor docs tweaks again
@JamesHenry I did a couple of modifications to the rule based on the discussion we had few days ago. |
@weirdpattern Would it be possible to ignore mapped types (https://www.typescriptlang.org/docs/handbook/advanced-types.html#mapped-types)? Not sure if this has been discussed yet or implemented in the current rule. |
@NeoReyad nope, I did not include mapped types... but it shouldn't be too complicated to implementing. What do you guys think? Or if you guys want to wait a little longer I can work on this in the next few days... |
on second thought, I think I'm gonna work on this tonight... I just realized the code doesn't handle those scenarios properly... |
Ok, I added |
Build is failing due to typescript version (2.0.3), works fine with latest version (2.1.x) as mapped types were introduced in this version release notes |
I'm sorry @weirdpattern but we cannot support TS 2.1.x in the parser yet - it is blocked on a TypeScript bug. See the upgrade issue for more details: eslint/typescript-eslint-parser#128 You will either have to remove the mapped types again or we can wait until after that issue is resolved to move forward with this PR. I'll leave it up to you! |
@weirdpattern I really appreciate the work you done on this plugin and others. Thanks for taking the time to include mapped types. I have looked into the typescript JsDoc bug that is blocking the parser from upgrading. I will try and get a pull request submitted this weekend. Hopefully we can have TypeScript patched and released in a few weeks. I think the only part that is breaking is the tests and not the plugin itself since it does not depend on SyntaxKind only the node.type string. Maybe we could just make those tests conditional? If you decided to remove the feature that is fine too but it'd be cool if we could include it in a separate typescript 2.1 branch, like we currently do with the parser. This way I could use the mapped type rule today instead of forking the project in my own repo. Thanks again. |
@NeoReyad it looks like it's going to be a while before we can move to v2.1.x. This bug was labeled TypeScript 2.2 and there is no due date yet... Re creating a 2.1 branch for this rule (and any other requiring v2.1.x), I'm all for it, but I'm just a contributor here, so I cannot create branches on this repo. I leave the decision to @nzakas and/or @JamesHenry, for now I'm just going to leave this PR as is. |
I see they have marked it as 2.2 milestone which i think is scheduled for march. One of the developer comments mentioned a quick fix. I will see if they can apply it to the 2.1 branch. |
I guess I can remove the mapped types from this PR, then create a new one that includes everything. The latter can be merged once TS 2.2 gets released and the parser supports it. I will work on this tomorrow. |
@JamesHenry I removed mapped types from this PR, we can merge now. |
Hey @weirdpattern, I am sorry for the insane delay on this. I have just merged in some important updates to the plugin from @corbinu, and released as 0.3.0. Are you available to update this PR to include all the latest work? |
- rename from no-type-literals to no-type-alias (thus broadening the scope of the rule). - rule now supports 4 configurations (allowAliases, allowCallbacks, allowLiterals and allowMappedTypes). - allowAliases supports values: true, false (and synonyms "always", "never"), "in-unions", "in-intersections", "in-unions-and-intersections". - allowCallbacks supports values: true, false (and synonyms "always", "never"). - allowLiterals supports values: true, false (and synonyms "always", "never"), "in-unions", "in-intersections", "in-unions-and-intersections". - allowMappedTypes supports values: true, false (and synonyms "always", "never"), "in-unions", "in-intersections", "in-unions-and-intersections". - add tests for each case and combinations - update documentation Remove mapped types as it's not currently supported. Add support for mapped types and aliases
c205a18
to
2d06065
Compare
@JamesHenry and @corbinu I've added the missing mapped types (see Feb 3 comment few lines above) and rebase the code to include the latest... we should be good to go, let me know otherwise... |
Thanks, @weirdpattern! |
This includes
New rule no-type-literal
Corresponding test
Corresponding documentation
Update to README.md to include the new rule