Hello, can anyone give me a tip on how to create t...
# javascript
d
Hello, can anyone give me a tip on how to create the wrappers for the following code? (Code in thead)
Copy code
export = dayjs;

declare function dayjs (date?: dayjs.ConfigType): dayjs.Dayjs

declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, strict?: boolean): dayjs.Dayjs

declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, locale?: string, strict?: boolean): dayjs.Dayjs

declare namespace dayjs {
  interface ConfigTypeMap {
    default: string | number | Date | Dayjs | null | undefined
  }

  // More Types
  //...

  class Dayjs {
    constructor (config?: ConfigType)
    /**
     * All Day.js objects are immutable. Still, `dayjs#clone` can create a clone of the current object if you need one.
     *
* dayjs().clone()// => Dayjs * dayjs(dayjs('2019-01-25')) // passing a Dayjs object to a constructor will also clone it *
Copy code
* Docs: <https://day.js.org/docs/en/parse/dayjs-clone>
     */
    clone(): Dayjs
    /**
     * This returns a `boolean` indicating whether the Day.js object contains a valid date or not.
     *
* dayjs().isValid()// => boolean *
Copy code
* Docs: <https://day.js.org/docs/en/parse/is-valid>
     */
    isValid(): boolean

//....
My attemp with the exception that
dayjs()
is unknown:
Copy code
@file:JsModule("dayjs")
@file:JsNonModule

package libs.antd.datepicker.dayjs

import kotlin.js.Date

@JsName("default")
external fun dayjs(date: Any? = definedExternally, format: Any? = definedExternally, locale: Any? = definedExternally, strict: Boolean? = definedExternally): Dayjs

@JsName("default")
external class Dayjs(config: Any? = definedExternally) {
    // 2023
    fun year(): Number

    // 0-11
    fun month(): Number

// More functions ....
t
You need separate file with
@file:JsQualifier("default")
for declarations from namespace
d
I'm afraid I need another tip. In the meantime, I had the complete definition generated with Dukat and have now received three files (1. contains the class and the types 2. contains the top-level functions, 3. contains types without further mapping). If I expand all files with the annotation, an error occurs and if I only specify the annotation on the package in the empty file, an error also occurs. Where or in which combination should the annotation be placed correctly?
t
Copy code
// 1.kt
@file:JsModule("dayjs")

extend()
locale()
class Dayjs

// 2.1.kt
@file:JsModule("dayjs")

@JsName("default")
fun dayjs()

@JsName("default")
fun dayjs()

@JsName("default")
fun dayjs()

// 2.2.kt
@JsModule("dayjs")
fun dayjs()

@JsModule("dayjs")
fun dayjs()

@JsModule("dayjs")
fun dayjs()
Looks like this 2.1 or 2.2 - it’s faster to test 🙂
d
This library probably does not want to be included. 😞 With the following inclusion, neither the function dayjs() nor the constructor Dayjs() can be called. Have I misunderstood or forgotten something?
@turansky Do you have another idea? Otherwise I would try to integrate the library via <script...>, then the simple external declarations should work.
t
You have just 3 variants for this case, 1 must work It’s faster to check it with
console.log
if you have
dayjs
in your dependencies
138 Views