Skip to content

Commit

Permalink
feat: add typescript support for useStore<T> (#1555)
Browse files Browse the repository at this point in the history
* feat: add typescript support for useStore<T>

* feat: enable typescript state for angular

* chore: add changeset

* chore: run prettier

* fix: issue with state methods not using type

* fix: issues mentioned in PR with any fo react state

* Update .changeset/quick-crabs-cough.md

---------

Co-authored-by: Sami Jaber <[email protected]>
  • Loading branch information
nmerget and samijaber authored Sep 30, 2024
1 parent 458e837 commit 068efab
Show file tree
Hide file tree
Showing 39 changed files with 3,673 additions and 102 deletions.
6 changes: 6 additions & 0 deletions .changeset/quick-crabs-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@builder.io/mitosis': patch
---

[Angular, React, Vue] feat: add typescript support for ``useStore``

88 changes: 88 additions & 0 deletions packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2644,6 +2644,50 @@ exports[`Alpine.js > jsx > Javascript Test > typeDependency 1`] = `
"
`;
exports[`Alpine.js > jsx > Javascript Test > typeExternalStore 1`] = `
"<div x-data=\\"typeExternalStore()\\">
Hello
<span x-html=\\"_name\\"></span>
!
</div>
<script>
document.addEventListener(\\"alpine:init\\", () => {
Alpine.data(\\"typeExternalStore\\", () => ({
_name: \\"test\\",
}));
});
</script>
"
`;
exports[`Alpine.js > jsx > Javascript Test > typeGetterStore 1`] = `
"<div x-data=\\"typeGetterStore()\\">
Hello
<span x-html=\\"name\\"></span>
!
</div>
<script>
document.addEventListener(\\"alpine:init\\", () => {
Alpine.data(\\"typeGetterStore\\", () => ({
name: \\"test\\",
getName() {
if (this.name === \\"a\\") {
return \\"b\\";
}
return this.name;
},
get test() {
return \\"test\\";
},
}));
});
</script>
"
`;
exports[`Alpine.js > jsx > Javascript Test > use-style 1`] = `
"<style>
button {
Expand Down Expand Up @@ -5391,6 +5435,50 @@ exports[`Alpine.js > jsx > Typescript Test > typeDependency 1`] = `
"
`;
exports[`Alpine.js > jsx > Typescript Test > typeExternalStore 1`] = `
"<div x-data=\\"typeExternalStore()\\">
Hello
<span x-html=\\"_name\\"></span>
!
</div>
<script>
document.addEventListener(\\"alpine:init\\", () => {
Alpine.data(\\"typeExternalStore\\", () => ({
_name: \\"test\\",
}));
});
</script>
"
`;
exports[`Alpine.js > jsx > Typescript Test > typeGetterStore 1`] = `
"<div x-data=\\"typeGetterStore()\\">
Hello
<span x-html=\\"name\\"></span>
!
</div>
<script>
document.addEventListener(\\"alpine:init\\", () => {
Alpine.data(\\"typeGetterStore\\", () => ({
name: \\"test\\",
getName() {
if (this.name === \\"a\\") {
return \\"b\\";
}
return this.name;
},
get test() {
return \\"test\\";
},
}));
});
</script>
"
`;
exports[`Alpine.js > jsx > Typescript Test > use-style 1`] = `
"<style>
button {
Expand Down
160 changes: 158 additions & 2 deletions packages/core/src/__tests__/__snapshots__/angular.import.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6530,6 +6530,80 @@ export class TypeDependencyModule {}
"
`;

exports[`Angular with Preserve Imports and File Extensions > jsx > Javascript Test > typeExternalStore 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component } from \\"@angular/core\\";

@Component({
selector: \\"type-external-store\\",
template: \`
<div>Hello {{_name}} !</div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class TypeExternalStore {
_name = \\"test\\";
}

@NgModule({
declarations: [TypeExternalStore],
imports: [CommonModule],
exports: [TypeExternalStore],
})
export class TypeExternalStoreModule {}
"
`;

exports[`Angular with Preserve Imports and File Extensions > jsx > Javascript Test > typeGetterStore 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component } from \\"@angular/core\\";

@Component({
selector: \\"type-getter-store\\",
template: \`
<div>Hello {{name}} !</div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class TypeGetterStore {
name = \\"test\\";
getName() {
if (this.name === \\"a\\") {
return \\"b\\";
}

return this.name;
}
get test() {
return \\"test\\";
}
}

@NgModule({
declarations: [TypeGetterStore],
imports: [CommonModule],
exports: [TypeGetterStore],
})
export class TypeGetterStoreModule {}
"
`;

exports[`Angular with Preserve Imports and File Extensions > jsx > Javascript Test > use-style 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down Expand Up @@ -6958,8 +7032,8 @@ export default class MyBasicComponent {
underscore_fn_name() {
return \\"bar\\";
}
age = 1;
sports = [\\"\\"];
age: number = 1;
sports: Array<string> = [\\"\\"];
}

@NgModule({
Expand Down Expand Up @@ -13822,6 +13896,88 @@ export class TypeDependencyModule {}
"
`;

exports[`Angular with Preserve Imports and File Extensions > jsx > Typescript Test > typeExternalStore 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component } from \\"@angular/core\\";

import { FooStore } from \\"./foo-store\\";

@Component({
selector: \\"type-external-store\\",
template: \`
<div>Hello {{_name}} !</div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class TypeExternalStore {
_name: FooStore[\\"_name\\"] = \\"test\\";
}

@NgModule({
declarations: [TypeExternalStore],
imports: [CommonModule],
exports: [TypeExternalStore],
})
export class TypeExternalStoreModule {}
"
`;

exports[`Angular with Preserve Imports and File Extensions > jsx > Typescript Test > typeGetterStore 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component } from \\"@angular/core\\";

type GetterStore = {
getName: () => string;
name: string;
get test(): string;
};

@Component({
selector: \\"type-getter-store\\",
template: \`
<div>Hello {{name}} !</div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class TypeGetterStore {
name: GetterStore[\\"name\\"] = \\"test\\";
getName(): GetterStore[\\"getName\\"] {
if (this.name === \\"a\\") {
return \\"b\\";
}

return this.name;
}
get test(): GetterStore[\\"test\\"] {
return \\"test\\";
}
}

@NgModule({
declarations: [TypeGetterStore],
imports: [CommonModule],
exports: [TypeGetterStore],
})
export class TypeGetterStoreModule {}
"
`;

exports[`Angular with Preserve Imports and File Extensions > jsx > Typescript Test > use-style 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down
Loading

0 comments on commit 068efab

Please sign in to comment.