New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent ending for type #7719
Comments
TS and flow are different systems, so I don't think you should necessarily aim for consistency between the two. In flow you pretty much only ever use OTOH, in TS the majority of the community uses The question then becomes "in TS, should prettier use the same delimiter for interface and object types, or should they use different characters?" |
@bradzacher I feel like I am going to lose this battle, but nevertheless, I favor the consistency of "objects looking like objects" over "objects looking like |
As mentioned in #6655 (comment), the official guide of TS uses semicolons.(The comment mentioned about only |
Object types in TS are anonymous interfaces. They can contain everything named interfaces can, e.g. method signatures, which look really strange with commas: let a: {
foo(): number,
bar(): string,
bar(baz: string): void,
(): void,
}; The relationship between object types and interfaces closely resembles the one between function expressions and function declarations. A function expression can be assigned to a variable ( The point I'm making is that using different formatting for object types and interfaces is very much like using different formatting for function expressions and function declarations. Not only inconsistent, it'd be also misleading, making object types and interfaces look more different than they actually are. |
interestingly, I just found out that prettier actually treats types and interfaces in flow differently: interface Test {
semi: string;
comma: string,
}
type Test = {
semi: string;
comma: string,
}; is formatted to the following with interface Test {
semi: string;
comma: string;
}
type Test = {
semi: string,
comma: string,
}; Whereas it's formatted to the following with interface Test {
semi: string;
comma: string;
}
type Test = {
semi: string;
comma: string;
}; |
@thorn0 Please see this @typescript-eslint/member-delimiter-style {
"rules": {
"@typescript-eslint/member-delimiter-style": [
"error",
{
"multiline": {
"delimiter": "comma",
"requireLast": true
},
"singleline": {
"delimiter": "comma",
"requireLast": true
}
}
]
}
} Having this configuration allows eslint to use comma instead of semicolon |
@seahindeniz And that's what that page says: "Semicolon style (default, preferred in TypeScript)". To avoid conflicts with Prettier, such formatting-related rules should be disabled. See https://prettier.io/docs/en/integrating-with-linters.html#eslint I'm closing this issue, see the justification above: #7719 (comment), #7719 (comment) |
@thorn0 yes, I have seen that before but there is also no restriction on the Typescript that enforces to use semicolons. The comma support has added in Typescript 1.5 see #1971 This is kind of look like the argument between tab and 2 or 4 spaces usage, isn't it? 😕 |
@seahindeniz I guess you've seen the option philosophy page and #40 too, right? This isn't going to happen. Tab width is a much more divisive issue than this. |
I didn't read that before and now did.
I can say and confirm that this isn't directly related to my use case. I'm simply referring is that Typescript has support for comma delimiter since 2015 and there is no enforcement that restricts us to use semicolon in type/interface definitions. We can agree there isn't going to be a bug in both usages, am I right? Btw. the tab width example is just to show that you there is no restriction between both usages, therefore, there shouldn't be for delimiters. |
I believe that the one we should have is what flow is outputting. Does someone have more context around why there's a difference here?
Flow
Typescript
The text was updated successfully, but these errors were encountered: