Skip to content

Commit

Permalink
Fix linter warning on dts module
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Oct 3, 2024
1 parent 2d7d81b commit 0d581cc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/routes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ declare const define: undefined | (((arg: unknown[], callback: () => unknown) =>
amd?: unknown;
});
declare const module: {
exports: any;
exports: unknown;
} | undefined;
14 changes: 8 additions & 6 deletions lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ RubyVariables.WRAPPER(
const ModuleReferences = {
CJS: {
define(routes) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
module.exports = routes;
if (module) {
module.exports = routes;
}
},
isSupported() {
return typeof module === "object";
},
},
AMD: {
define(routes) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
define([], function () {
return routes;
});
if (define) {
define([], function () {
return routes;
});
}
},
isSupported() {
return typeof define === "function" && !!define.amd;
Expand Down
16 changes: 9 additions & 7 deletions lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ declare const define:
| undefined
| (((arg: unknown[], callback: () => unknown) => void) & { amd?: unknown });

declare const module: { exports: any } | undefined;
declare const module: { exports: unknown } | undefined;

// eslint-disable-next-line
RubyVariables.WRAPPER(
Expand Down Expand Up @@ -148,19 +148,21 @@ RubyVariables.WRAPPER(
const ModuleReferences: Record<ModuleType, ModuleDefinition> = {
CJS: {
define(routes) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
module!.exports = routes;
if (module) {
module.exports = routes;
}
},
isSupported() {
return typeof module === "object";
},
},
AMD: {
define(routes) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
define!([], function () {
return routes;
});
if (define) {
define([], function () {
return routes;
});
}
},
isSupported() {
return typeof define === "function" && !!define.amd;
Expand Down
5 changes: 4 additions & 1 deletion lib/tasks/js_routes.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ namespace :js do
task routes: :environment do
require "js-routes"
JsRoutes.generate!
JsRoutes.definitions! if JsRoutes.configuration.modern?
end

namespace :routes do
desc "Make a js file with all rails route URL helpers and typescript definitions for them"
task typescript: "js:routes" do
JsRoutes.definitions!
ActiveSupport::Deprecation.warn(
"`js:routes:typescript` task is deprecated. Please use `js:routes` instead."
)
end
end
end
2 changes: 1 addition & 1 deletion spec/js_routes/module_types/dts/routes.spec.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ declare const define: undefined | (((arg: unknown[], callback: () => unknown) =>
amd?: unknown;
});
declare const module: {
exports: any;
exports: unknown;
} | undefined;
export const configure: RouterExposedMethods['configure'];

Expand Down

0 comments on commit 0d581cc

Please sign in to comment.