From a3c29eb508ff6d4fd1fd0b3b9611fd2bb320d537 Mon Sep 17 00:00:00 2001 From: Simon Vandel Sillesen Date: Thu, 10 Feb 2022 18:52:57 +0100 Subject: [PATCH] add unit test that shows `Date` is rendered in TS type in interface --- examples/napi/__test__/typegen.spec.ts.md | 4 ++++ examples/napi/__test__/typegen.spec.ts.snap | Bin 2656 -> 2681 bytes examples/napi/index.d.ts | 4 ++++ examples/napi/src/date.rs | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/examples/napi/__test__/typegen.spec.ts.md b/examples/napi/__test__/typegen.spec.ts.md index 6f3cce0f..4e6eb413 100644 --- a/examples/napi/__test__/typegen.spec.ts.md +++ b/examples/napi/__test__/typegen.spec.ts.md @@ -43,6 +43,10 @@ Generated by [AVA](https://avajs.dev). export function dateToNumber(input: Date): number␊ export function chronoDateToMillis(input: Date): number␊ export function chronoDateAdd1Minute(input: Date): Date␊ + export interface Dates {␊ + start: Date␊ + end?: Date | undefined | null␊ + }␊ export function eitherStringOrNumber(input: string | number): number␊ export function returnEither(input: number): string | number␊ export function either3(input: string | number | boolean): number␊ diff --git a/examples/napi/__test__/typegen.spec.ts.snap b/examples/napi/__test__/typegen.spec.ts.snap index d07cb6c3f46a76a2e4964753de91fa4deae95afc..335738c18ebe44ba50ae103449c3727e1fbb1f1a 100644 GIT binary patch literal 2681 zcmV-<3WoJTRzVr!PG^uRG=ijAxMQ>Aj@{vPAnU?+|9yk zY=-1WnwXklI78d2*Fg8B&wcJovHOMngq|})QbUoH>>z;yafatU=Q{j#=tnZRRKNVj zG}jTk`KubsGz!Ux36@aJNFbAh1)At-%t*+FWXL1Nm7p;|YW2&nVMsOoVf9~sc=V@7 z`0sareDuxluUDTvCR#;Y=uXHL^&>_eKU;xKW;UNVo489;EuZ8(L*h?Kzk9s@3H(NKzLO1}NJV>aftQo%o`jHv0vmyvmW z{;rcPFFIrZTX!pWAj)Gh7;{D7kAm((X_O!rz^r$6_qu2A2S4?WP6r(#(uvQK9AcP? z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kr1?Ao+6_8TIF;2E=2Z0;vHgIK*oONZm7o($3ue7<*1G?@9E%Z-K-huk0M&Tu zw=Q02{Zct?5?Wx}W!c0Tu}Ldq4C_W~hHIsS05}y77L_~^=z+}G4T~zfH-pBQPF&Vy z%-?HScZ?P7qHWYhQH292CTa7PHz6qx<^8d%G6oZa)U~UO5|H6W;0B)gN}V z09f*!E)PG^UJ|Q-)wSXsT}a3TZ{tD)CrZPA1M&Uu-wWXyvbzf!4N*ypuyMCjDn}g= zm@vp0;22)aM#V!uk!>mQqv8%R4>LwHFCQun1}Hn+x0co6W(Ao2Mo{5RIR=uG5f07w z_rpyMS-9Y7zdwH4Jw5F9tW;2OeY*M6_Ez29sfls`THkm*MbcqiK?#876Z(L18bxgy zX6HkuL^*s6b`s%dIfF^kRf(VOJ@LKI2T*(*TZG3N+ilpkvlZIFi;o4jqSZG2u<%;? Oaq0h%j0%N_A^-pt{rtoL diff --git a/examples/napi/index.d.ts b/examples/napi/index.d.ts index 9f9da35d..2a6ae7e7 100644 --- a/examples/napi/index.d.ts +++ b/examples/napi/index.d.ts @@ -33,6 +33,10 @@ export function returnJsFunction(): (...args: any[]) => any export function dateToNumber(input: Date): number export function chronoDateToMillis(input: Date): number export function chronoDateAdd1Minute(input: Date): Date +export interface Dates { + start: Date + end?: Date | undefined | null +} export function eitherStringOrNumber(input: string | number): number export function returnEither(input: number): string | number export function either3(input: string | number | boolean): number diff --git a/examples/napi/src/date.rs b/examples/napi/src/date.rs index d1d00ca5..f13ee76a 100644 --- a/examples/napi/src/date.rs +++ b/examples/napi/src/date.rs @@ -15,3 +15,9 @@ fn chrono_date_to_millis(input: chrono::DateTime) -> i64 { fn chrono_date_add_1_minute(input: chrono::DateTime) -> chrono::DateTime { input + Duration::minutes(1) } + +#[napi(object)] +pub struct Dates { + pub start: chrono::DateTime, + pub end: Option>, +}