Merge pull request #1155 from napi-rs/invalid-return-type
fix(napi-derive): invalid TypeScript return type
This commit is contained in:
commit
8ee7df10bd
6 changed files with 12 additions and 9 deletions
1
.github/workflows/test.yaml
vendored
1
.github/workflows/test.yaml
vendored
|
@ -68,5 +68,6 @@ jobs:
|
|||
run: |
|
||||
yarn build:test
|
||||
yarn test --verbose
|
||||
yarn tsc -p examples/napi/tsconfig.json --noEmit
|
||||
env:
|
||||
RUST_BACKTRACE: 1
|
||||
|
|
|
@ -181,6 +181,7 @@ static KNOWN_TYPES: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
|
|||
("Either5", "{} | {} | {} | {} | {}"),
|
||||
("unknown", "unknown"),
|
||||
("Null", "null"),
|
||||
("JsNull", "null"),
|
||||
("null", "null"),
|
||||
("Symbol", "symbol"),
|
||||
("JsSymbol", "symbol"),
|
||||
|
@ -262,7 +263,7 @@ pub fn ty_to_ts_type(ty: &Type, is_return_ty: bool, is_struct_field: bool) -> (S
|
|||
if is_struct_field {
|
||||
arg.to_string()
|
||||
} else if is_return_ty {
|
||||
format!("{}?", arg)
|
||||
format!("{} | null", arg)
|
||||
} else {
|
||||
format!("{} | undefined | null", arg)
|
||||
},
|
||||
|
|
|
@ -106,7 +106,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
export function xxh64Alias(input: Buffer): bigint␊
|
||||
export function getMapping(): Record<string, number>␊
|
||||
export function sumMapping(nums: Record<string, number>): number␊
|
||||
export function mapOption(val?: number | undefined | null): number?␊
|
||||
export function mapOption(val?: number | undefined | null): number | null␊
|
||||
export function returnNull(): null␊
|
||||
export function returnUndefined(): void␊
|
||||
export function add(a: number, b: number): number␊
|
||||
|
@ -115,7 +115,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
export function createObj(): object␊
|
||||
export function getGlobal(): typeof global␊
|
||||
export function getUndefined(): void␊
|
||||
export function getNull(): JsNull␊
|
||||
export function getNull(): null␊
|
||||
export interface AllOptionalObject {␊
|
||||
name?: string␊
|
||||
age?: number␊
|
||||
|
@ -243,7 +243,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
export type JsAssets = Assets␊
|
||||
export class Assets {␊
|
||||
constructor()␊
|
||||
get(id: number): JsAsset?␊
|
||||
get(id: number): JsAsset | null␊
|
||||
}␊
|
||||
export type JsAsset = Asset␊
|
||||
export class Asset {␊
|
||||
|
|
Binary file not shown.
6
examples/napi/index.d.ts
vendored
6
examples/napi/index.d.ts
vendored
|
@ -96,7 +96,7 @@ export function tsRename(a: { foo: number }): string[]
|
|||
export function xxh64Alias(input: Buffer): bigint
|
||||
export function getMapping(): Record<string, number>
|
||||
export function sumMapping(nums: Record<string, number>): number
|
||||
export function mapOption(val?: number | undefined | null): number?
|
||||
export function mapOption(val?: number | undefined | null): number | null
|
||||
export function returnNull(): null
|
||||
export function returnUndefined(): void
|
||||
export function add(a: number, b: number): number
|
||||
|
@ -105,7 +105,7 @@ export function listObjKeys(obj: object): Array<string>
|
|||
export function createObj(): object
|
||||
export function getGlobal(): typeof global
|
||||
export function getUndefined(): void
|
||||
export function getNull(): JsNull
|
||||
export function getNull(): null
|
||||
export interface AllOptionalObject {
|
||||
name?: string
|
||||
age?: number
|
||||
|
@ -233,7 +233,7 @@ export class NinjaTurtle {
|
|||
export type JsAssets = Assets
|
||||
export class Assets {
|
||||
constructor()
|
||||
get(id: number): JsAsset?
|
||||
get(id: number): JsAsset | null
|
||||
}
|
||||
export type JsAsset = Asset
|
||||
export class Asset {
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"rootDir": "__test__",
|
||||
"target": "ES2018"
|
||||
"target": "ES2018",
|
||||
"skipLibCheck": false
|
||||
},
|
||||
"exclude": ["dist", "index.d.ts"]
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue