oxc/crates/oxc_codegen/tests/integration/ts.rs

57 lines
2 KiB
Rust

use crate::snapshot;
#[test]
fn ts() {
let cases = [
"let x: string = `\\x01`;",
"function foo<T extends string>(x: T, y: string, ...restOfParams: Omit<T, 'x'>): T {\n\treturn x;\n}",
"let x: string[] = ['abc', 'def', 'ghi'];",
"let x: Array<string> = ['abc', 'def', 'ghi',];",
"let x: [string, number] = ['abc', 123];",
"let x: string | number = 'abc';",
"let x: string & number = 'abc';",
"let x: typeof String = 'string';",
"let x: keyof string = 'length';",
"let x: keyof typeof String = 'length';",
"let x: string['length'] = 123;",
"function isString(value: unknown): asserts value is string {
if (typeof value !== 'string') {
throw new Error('Not a string');
}
}",
"import type { Foo } from 'foo';",
"import { Foo, type Bar } from 'foo';",
"export { Foo, type Bar } from 'foo';",
"type A<T> = { [K in keyof T as K extends string ? B<K> : K ]: T[K] }",
"class A {readonly type = 'frame'}",
"let foo: { <T>(t: T): void }",
"let foo: { new <T>(t: T): void }",
"function <const T>(){}",
"class A {m?(): void}",
"class A {constructor(public readonly a: number) {}}",
"abstract class A {private abstract static m() {}}",
"abstract class A {private abstract static readonly prop: string}",
"a = x!;",
"b = (x as y);",
"c = foo<string>;",
"d = x satisfies y;",
"export @x declare abstract class C {}",
"div<T>``",
"export type Component<Props = any> = Foo;",
"
export type Component<
Props = any,
RawBindings = any,
D = any,
C extends ComputedOptions = ComputedOptions,
M extends MethodOptions = MethodOptions,
E extends EmitsOptions | Record<string, any[]> = {},
S extends Record<string, any> = any,
> =
| ConcreteComponent<Props, RawBindings, D, C, M, E, S>
| ComponentPublicInstanceConstructor<Props>
"
];
snapshot("ts", &cases);
}