diff --git a/tests/typescript_as/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_as/__snapshots__/jsfmt.spec.js.snap index a90a79d45674..073735fef7bc 100644 --- a/tests/typescript_as/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_as/__snapshots__/jsfmt.spec.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`as.js 1`] = ` +exports[`as.ts 1`] = ` ====================================options===================================== parsers: ["typescript"] printWidth: 80 @@ -9,9 +9,12 @@ printWidth: 80 const name = (description as DescriptionObject).name || (description as string); this.isTabActionBar((e.target || e.srcElement) as HTMLElement); (originalError ? wrappedError(errMsg, originalError) : Error(errMsg)) as InjectionError; -'current' in (props.pagination as Object) -start + (yearSelectTotal as number) -scrollTop > (visibilityHeight as number) +'current' in (props.pagination as Object); +('current' in props.pagination) as Object; +start + (yearSelectTotal as number); +(start + yearSelectTotal) as number; +scrollTop > (visibilityHeight as number); +(scrollTop > visibilityHeight) as number; export default class Column extends (RcTable.Column as React.ComponentClass,ColumnProps,ColumnProps,ColumnProps>) {} export const MobxTypedForm = class extends (Form as { new (): any }) {} export abstract class MobxTypedForm1 extends (Form as { new (): any }) {} @@ -35,6 +38,14 @@ const state = JSON.stringify({ (bValue as boolean) ? 0 : -1; bValue ? 0 : -1; +const value1 = thisIsAReallyReallyReallyReallyReallyLongIdentifier as SomeInterface; +const value2 = thisIsAnIdentifier as thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongInterface; +const value3 = thisIsAReallyLongIdentifier as (SomeInterface | SomeOtherInterface); +const value4 = thisIsAReallyLongIdentifier as { prop1: string, prop2: number, prop3: number }[]; +const value5 = thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyLongIdentifier as [string, number]; + +const iter1 = createIterator(this.controller, child, this.tag as SyncFunctionComponent); +const iter2 = createIterator(self.controller, child, self.tag as SyncFunctionComponent); =====================================output===================================== const name = (description as DescriptionObject).name || (description as string); @@ -43,8 +54,11 @@ this.isTabActionBar((e.target || e.srcElement) as HTMLElement); ? wrappedError(errMsg, originalError) : Error(errMsg)) as InjectionError; "current" in (props.pagination as Object); +("current" in props.pagination) as Object; start + (yearSelectTotal as number); +(start + yearSelectTotal) as number; scrollTop > (visibilityHeight as number); +(scrollTop > visibilityHeight) as number; export default class Column extends (RcTable.Column as React.ComponentClass< ColumnProps, ColumnProps, @@ -73,6 +87,104 @@ const state = JSON.stringify({ (bValue as boolean) ? 0 : -1; bValue ? 0 : -1; +const value1 = thisIsAReallyReallyReallyReallyReallyLongIdentifier as SomeInterface; +const value2 = thisIsAnIdentifier as thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongInterface; +const value3 = thisIsAReallyLongIdentifier as + | SomeInterface + | SomeOtherInterface; +const value4 = thisIsAReallyLongIdentifier as { + prop1: string; + prop2: number; + prop3: number; +}[]; +const value5 = thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyLongIdentifier as [ + string, + number +]; + +const iter1 = createIterator( + this.controller, + child, + this.tag as SyncFunctionComponent +); +const iter2 = createIterator( + self.controller, + child, + self.tag as SyncFunctionComponent +); + +================================================================================ +`; + +exports[`assignment.ts 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +export const LOG_LEVEL = { + EMERGENCY: 0, + ALERT: 1, + CRITICAL: 2, + ERROR: 3, + WARNING: 4, + NOTICE: 5, + INFO: 6, + DEBUG: 7, +} as const; + +const TYPE_MAP = { + 'character device': 'special', + 'character special file': 'special', + directory: 'directory', + 'regular file': 'file', + socket: 'socket', + 'symbolic link': 'link', +} as Foo; + +this.previewPlayerHandle = (setInterval(async () => { + if (this.previewIsPlaying) { + await this.fetchNextPreviews(); + this.currentPreviewIndex++; + } +}, this.refreshDelay) as unknown) as number; + +this.intervalID = (setInterval(() => { + self.step(); +}, 30) as unknown) as number; + +=====================================output===================================== +export const LOG_LEVEL = { + EMERGENCY: 0, + ALERT: 1, + CRITICAL: 2, + ERROR: 3, + WARNING: 4, + NOTICE: 5, + INFO: 6, + DEBUG: 7, +} as const; + +const TYPE_MAP = { + "character device": "special", + "character special file": "special", + directory: "directory", + "regular file": "file", + socket: "socket", + "symbolic link": "link", +} as Foo; + +this.previewPlayerHandle = (setInterval(async () => { + if (this.previewIsPlaying) { + await this.fetchNextPreviews(); + this.currentPreviewIndex++; + } +}, this.refreshDelay) as unknown) as number; + +this.intervalID = (setInterval(() => { + self.step(); +}, 30) as unknown) as number; + ================================================================================ `; @@ -89,3 +201,27 @@ export default (function log() {} as typeof console.log); ================================================================================ `; + +exports[`return.ts 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +function foo() { + return { + foo: 1, + bar: 2, + } as Foo; +} + +=====================================output===================================== +function foo() { + return { + foo: 1, + bar: 2, + } as Foo; +} + +================================================================================ +`; diff --git a/tests/typescript_as/as.js b/tests/typescript_as/as.js deleted file mode 100644 index 596bdd8d2c92..000000000000 --- a/tests/typescript_as/as.js +++ /dev/null @@ -1,29 +0,0 @@ -const name = (description as DescriptionObject).name || (description as string); -this.isTabActionBar((e.target || e.srcElement) as HTMLElement); -(originalError ? wrappedError(errMsg, originalError) : Error(errMsg)) as InjectionError; -'current' in (props.pagination as Object) -start + (yearSelectTotal as number) -scrollTop > (visibilityHeight as number) -export default class Column extends (RcTable.Column as React.ComponentClass,ColumnProps,ColumnProps,ColumnProps>) {} -export const MobxTypedForm = class extends (Form as { new (): any }) {} -export abstract class MobxTypedForm1 extends (Form as { new (): any }) {} -({}) as {}; -function*g() { - const test = (yield 'foo') as number; -} -async function g1() { - const test = (await 'foo') as number; -} -({}) as X; -() => ({}) as X; -const state = JSON.stringify({ - next: window.location.href, - nonce, -} as State); - -(foo.bar as Baz) = [bar]; -(foo.bar as any)++; - -(bValue as boolean) ? 0 : -1; -bValue ? 0 : -1; - diff --git a/tests/typescript_as/as.ts b/tests/typescript_as/as.ts new file mode 100644 index 000000000000..cfdaced54745 --- /dev/null +++ b/tests/typescript_as/as.ts @@ -0,0 +1,40 @@ +const name = (description as DescriptionObject).name || (description as string); +this.isTabActionBar((e.target || e.srcElement) as HTMLElement); +(originalError ? wrappedError(errMsg, originalError) : Error(errMsg)) as InjectionError; +'current' in (props.pagination as Object); +('current' in props.pagination) as Object; +start + (yearSelectTotal as number); +(start + yearSelectTotal) as number; +scrollTop > (visibilityHeight as number); +(scrollTop > visibilityHeight) as number; +export default class Column extends (RcTable.Column as React.ComponentClass,ColumnProps,ColumnProps,ColumnProps>) {} +export const MobxTypedForm = class extends (Form as { new (): any }) {} +export abstract class MobxTypedForm1 extends (Form as { new (): any }) {} +({}) as {}; +function*g() { + const test = (yield 'foo') as number; +} +async function g1() { + const test = (await 'foo') as number; +} +({}) as X; +() => ({}) as X; +const state = JSON.stringify({ + next: window.location.href, + nonce, +} as State); + +(foo.bar as Baz) = [bar]; +(foo.bar as any)++; + +(bValue as boolean) ? 0 : -1; +bValue ? 0 : -1; + +const value1 = thisIsAReallyReallyReallyReallyReallyLongIdentifier as SomeInterface; +const value2 = thisIsAnIdentifier as thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongInterface; +const value3 = thisIsAReallyLongIdentifier as (SomeInterface | SomeOtherInterface); +const value4 = thisIsAReallyLongIdentifier as { prop1: string, prop2: number, prop3: number }[]; +const value5 = thisIsAReallyReallyReallyReallyReallyReallyReallyReallyReallyLongIdentifier as [string, number]; + +const iter1 = createIterator(this.controller, child, this.tag as SyncFunctionComponent); +const iter2 = createIterator(self.controller, child, self.tag as SyncFunctionComponent); diff --git a/tests/typescript_as/assignment.ts b/tests/typescript_as/assignment.ts new file mode 100644 index 000000000000..8d0fb62077cd --- /dev/null +++ b/tests/typescript_as/assignment.ts @@ -0,0 +1,30 @@ +export const LOG_LEVEL = { + EMERGENCY: 0, + ALERT: 1, + CRITICAL: 2, + ERROR: 3, + WARNING: 4, + NOTICE: 5, + INFO: 6, + DEBUG: 7, +} as const; + +const TYPE_MAP = { + 'character device': 'special', + 'character special file': 'special', + directory: 'directory', + 'regular file': 'file', + socket: 'socket', + 'symbolic link': 'link', +} as Foo; + +this.previewPlayerHandle = (setInterval(async () => { + if (this.previewIsPlaying) { + await this.fetchNextPreviews(); + this.currentPreviewIndex++; + } +}, this.refreshDelay) as unknown) as number; + +this.intervalID = (setInterval(() => { + self.step(); +}, 30) as unknown) as number; diff --git a/tests/typescript_as/return.ts b/tests/typescript_as/return.ts new file mode 100644 index 000000000000..97baa447576f --- /dev/null +++ b/tests/typescript_as/return.ts @@ -0,0 +1,6 @@ +function foo() { + return { + foo: 1, + bar: 2, + } as Foo; +}