将TS语法转换为JSDOC

huangapple go评论72阅读模式
英文:

converting TS syntax to JSDOC

问题

import { SvelteKitAuth } from '@auth/sveltekit';

/**
 * @type {import('@auth/sveltekit').SvelteKitAuthConfig}
 */
export let svelteKitAuthConfig;

/**
 * @type {import('@auth/core/providers').Provider}
 */
export let provider;

config: svelteKitAuthConfig = {
  providers: [
    Auth0Provider({
      id: 'auth0',
      name: 'Auth0',
      clientId: '-client-id-',
      clientSecret: '-client-secret-',
      issuer: 'https://dev-****.auth0.com/', // <- remember to add trailing `/`
      wellKnown: 'https://dev-****.auth0.com/.well-known/openid-configuration',
    }) as provider, // <-- Error here
  ],
  secret: '-any-random-string-',
  debug: true,
  session: {
    maxAge: 1800, // 30 mins
  },
};
英文:

I am trying to convert a code snippet from TS to plain javascript jsdoc. Is there a good wiki that explains this ?

before

  import { SvelteKitAuth, type SvelteKitAuthConfig } from &#39;@auth/sveltekit&#39;;
  import type { Provider } from &#39;@auth/core/providers&#39;;

after:

 import { SvelteKitAuth  } from &#39;@auth/sveltekit&#39;;
/** @type {import(&#39;@auth/sveltekit&#39;).SvelteKitAuthConfig} */
export let svelteKitAuthConfig 
/** @type {import(&#39;@auth/core/providers&#39;).Provider}; */
export let provider

I have error "unexpected token" when I try to reference provider

config: svelteKitAuthConfig = {
  providers: [
    Auth0Provider({
      id: &#39;auth0&#39;,
      name: &#39;Auth0&#39;,
      clientId: &#39;-client-id-&#39;,
      clientSecret: &#39;-client-secret-&#39;,
      issuer: &#39;https://dev-****.auth0.com/&#39;,  // &lt;- remember to add trailing `/` 
      wellKnown: &#39;https://dev-****.auth0.com/.well-known/openid-configuration&#39;
    }) as provider   &lt;-- Error here
  ],
  secret: &#39;-any-random-string-&#39;,
  debug: true,
  session: {
    maxAge: 1800 // 30 mins
  }
};

答案1

得分: 0

as是TypeScript语法,它在JS中不存在。(同时,provider是一个值,而不是一个类型。)

你可以尝试在你要类型化的值之前使用另一个/** @type {...} */注释。可能首先将其提取到一个单独的const中。

英文:

as is TypeScript syntax, it does not exist in JS. (Also provider is a value, not a type.)

You can try to use another /** @type {...} */ annotation before the value you are trying to type. Possibly extract it to a separate const first.

huangapple
  • 本文由 发表于 2023年8月4日 06:08:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76831857.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定