Skip to content

Commit

Permalink
test: added string literal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Aug 15, 2023
1 parent 68dae7b commit 87f806c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
24 changes: 24 additions & 0 deletions test/schemas/string.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
generator client {
provider = "prisma-client-js"
output = "../target/string"
}

generator json {
provider = "node ./index.js"
namespace = "PStringJson"
}

datasource db {
provider = "postgresql"
url = ""
}

model Model {
id Int @id @default(autoincrement())
untyped String
/// [WithType]
typed String
/// !['A' | 'B']
literal String
}
2 changes: 2 additions & 0 deletions test/schemas/unknown.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ model Model {
id Int @id @default(autoincrement())
field Json
str String
int Int
}
22 changes: 22 additions & 0 deletions test/types/string.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expectNotType, expectType } from 'tsd';
import { Model } from '../target/string/index';

declare global {
export namespace PStringJson {
type WithType = 'C' | 'D';
}
}

expectType<Model>({
id: 0,
untyped: '' as string,
typed: 'C' as PStringJson.WithType,
literal: 'A' as 'A' | 'B'
});

expectNotType<Model>({
id: 0,
untyped: 'Mesquita' as string,
typed: 'D' as string,
literal: 'D' as string
});
15 changes: 13 additions & 2 deletions test/types/unknown.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@ import { Model } from '../target/unknown/index';

expectType<Model>({
id: 0,
field: {} as unknown
field: {} as unknown,
str: '' as string,
int: 0 as number,
});

expectNotType<Model>({
id: 0,
field: {} as any
field: {} as any,
str: {} as unknown,
int: 0 as unknown,
});

expectNotType<Model>({
id: 0,
field: {} as any,
str: {} as any,
int: 0 as any
});

0 comments on commit 87f806c

Please sign in to comment.