I'm using Typescript and Prettier and every time I cast something in the first line of the function Prettier puts a semicolon as a first character.
Why? It seems unnecessary. Am I wrong?
I read the Rationale but still I cannot understand why we need to put the first semicolon there.
Prettier 2.2.1 Playground link
--parser typescript
--no-semi
Input:
function example() {
(this as MyType).method() // useless semicolon will be placed here
;(f as any).y = fy // the semicolon here is ok
return f
}
Output:
function example() {
;(this as MyType).method() // useless semicolon here
;(f as any).y = fy // the semicolon here is ok
return f
}
Expected behavior:
The first semicolon must not be put.
I opened an issue on the Prettier repo but they suggested I ask here.
***UPDATE:
If I use prettier defaults I have issues too, see this example:
Prettier 2.2.1 Playground link
--parser typescript
Input:
export function inputSelect(e: MouseEvent): void {
console.log("Test this")
(e.target as HTMLInputElement)?.select();
}
Output:
export function inputSelect(e: MouseEvent): void {
console
.log("Test this")(e.target as HTMLInputElement)
?.select();
}
Expected behavior:
It should put the semicolon at the end of the console.log()
.