mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-01-12 22:46:30 +08:00
Fix TypeScript decorator support (#5783)
* Fix TypeScript decorator support * Update babel flow override * WIP
This commit is contained in:
6
test/fixtures/typescript/src/App.test.ts
vendored
6
test/fixtures/typescript/src/App.test.ts
vendored
@@ -6,3 +6,9 @@ it('reads a typescript file with no syntax error', () => {
|
||||
expect(App.foo.baz!.n).toBe(123);
|
||||
expect(app.n).toBe(123);
|
||||
});
|
||||
|
||||
it('supports decorators', () => {
|
||||
const app = new App();
|
||||
expect((app as any).annotated).toBe(true);
|
||||
expect(app.decorated).toBe(42);
|
||||
});
|
||||
|
||||
13
test/fixtures/typescript/src/App.ts
vendored
13
test/fixtures/typescript/src/App.ts
vendored
@@ -10,10 +10,23 @@ type MyObject = Pick<MyType, 'bar' | 'baz'>;
|
||||
class App {
|
||||
static foo: MyObject = { bar: true, baz: { n: 123 } };
|
||||
n = App.foo.baz!.n;
|
||||
@propertyDecorator
|
||||
decorated;
|
||||
}
|
||||
|
||||
function annotation(target: any) {
|
||||
target.annotated = true;
|
||||
}
|
||||
|
||||
function propertyDecorator(target: any, key: string) {
|
||||
if (delete target[key]) {
|
||||
Object.defineProperty(target, key, {
|
||||
get() {
|
||||
return 42;
|
||||
},
|
||||
enumerable: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
||||
Reference in New Issue
Block a user