Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove extraneous typeof operator #611

Merged
merged 1 commit into from Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/good-pugs-share.md
@@ -0,0 +1,5 @@
---
"counterfact": patch
---

got a little carried away with typeof; it's needed for the instance, not the class
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -8,7 +8,7 @@

BREAKING CHANGE:

- the main $.context.ts file needs an extra line: `export type ContextType = typeof Context;`
- the main $.context.ts file needs an extra line: `export type ContextType = Context;`
- $.context.ts files below the root need to change to `export type { ContextType } from "../$.context";`
- if you modified any of the $.context.ts files below the root, treat the first bullet applies

Expand Down
2 changes: 1 addition & 1 deletion src/migrations/0.27.js
Expand Up @@ -18,7 +18,7 @@ function processFile(filePath) {
}

if (content.includes("export default new Context")) {
writeFileSync(filePath, "export type ContextType = typeof Context;\n", {
writeFileSync(filePath, "export type ContextType = Context;\n", {
flag: "a",
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/typescript-generator/context-type-coder.js
Expand Up @@ -26,7 +26,7 @@ export class ContextTypeCoder extends Coder {

write(script) {
if (script.path === "paths/$.context.ts") {
return "typeof Context";
return "Context";
}

return { raw: 'export type { ContextType } from "../$.context"' };
Expand Down
12 changes: 6 additions & 6 deletions test/typescript-generator/__snapshots__/generate.test.ts.snap
Expand Up @@ -181,7 +181,7 @@ class Context {
},
"ContextType" => Object {
"beforeExport": "",
"code": "typeof Context",
"code": "Context",
"done": true,
"id": "ContextTypeCoder",
"isDefault": false,
Expand Down Expand Up @@ -448,7 +448,7 @@ class Context {
},
"ContextType" => Object {
"beforeExport": "",
"code": "typeof Context",
"code": "Context",
"done": true,
"id": "ContextTypeCoder",
"isDefault": false,
Expand Down Expand Up @@ -719,7 +719,7 @@ class Context {
},
"ContextType" => Object {
"beforeExport": "",
"code": "typeof Context",
"code": "Context",
"done": true,
"id": "ContextTypeCoder",
"isDefault": false,
Expand Down Expand Up @@ -4017,7 +4017,7 @@ class Context {
},
"ContextType" => Object {
"beforeExport": "",
"code": "typeof Context",
"code": "Context",
"done": true,
"id": "ContextTypeCoder",
"isDefault": false,
Expand Down Expand Up @@ -4167,7 +4167,7 @@ class Context {
},
"ContextType" => Object {
"beforeExport": "",
"code": "typeof Context",
"code": "Context",
"done": true,
"id": "ContextTypeCoder",
"isDefault": false,
Expand Down Expand Up @@ -5712,7 +5712,7 @@ class Context {
},
"ContextType" => Object {
"beforeExport": "",
"code": "typeof Context",
"code": "Context",
"done": true,
"id": "ContextTypeCoder",
"isDefault": false,
Expand Down
4 changes: 2 additions & 2 deletions test/typescript-generator/context-type-coder.test.js
Expand Up @@ -48,7 +48,7 @@ describe("a ContextTypeCoder", () => {
);
});

it("exports typeof Context in the root", async () => {
it("exports ContextType in the root", async () => {
const coder = new ContextTypeCoder(new Requirement({}, "#/paths"));

const dummyScriptWithRootPath = {
Expand All @@ -57,7 +57,7 @@ describe("a ContextTypeCoder", () => {
};

await expect(format(coder.write(dummyScriptWithRootPath))).resolves.toBe(
await format("typeof Context"),
await format("Context"),
);
});
});