Skip to content

Commit

Permalink
daml-ledger.ts: Simplify types of *ByKey operations (digital-asset#4202)
Browse files Browse the repository at this point in the history
The current type signature adds complexity which is unjustified in my
opinion. Who would expect meaningful results when specifying a template
by key `undefined`?

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
hurryabit authored and mergify[bot] committed Jan 24, 2020
1 parent 3496ce0 commit 3a4d356
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions language-support/ts/daml-ledger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ class Ledger {
/**
* Fetch a contract by its key.
*/
async lookupByKey<T extends object, K>(template: Template<T, K>, key: K extends undefined ? never : K): Promise<CreateEvent<T, K> | null> {
async lookupByKey<T extends object, K>(template: Template<T, K>, key: K): Promise<CreateEvent<T, K> | null> {
if (key === undefined) {
throw Error(`Cannot lookup by key on template ${template.templateId} because it does not define a key.`);
}
const payload = {
templateId: template.templateId,
key,
Expand Down Expand Up @@ -186,7 +189,10 @@ class Ledger {
/**
* Exercise a choice on a contract identified by its contract key.
*/
async exerciseByKey<T extends object, C, R, K>(choice: Choice<T, C, R, K>, key: K extends undefined ? never : K, argument: C): Promise<[R, Event<object>[]]> {
async exerciseByKey<T extends object, C, R, K>(choice: Choice<T, C, R, K>, key: K, argument: C): Promise<[R, Event<object>[]]> {
if (key === undefined) {
throw Error(`Cannot exercise by key on template ${choice.template().templateId} because it does not define a key.`);
}
const payload = {
templateId: choice.template().templateId,
key,
Expand Down
5 changes: 4 additions & 1 deletion language-support/ts/daml-ledger/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
"declaration": true,
"sourceMap": true
},
"include": ["**/*.ts"]
"include": [
"**/*.ts",
"lib/**/*"
]
}
5 changes: 4 additions & 1 deletion language-support/ts/daml-types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"sourceMap": true
},
"include": ["**/*.ts"],
"exclude": ["**/*.test.ts"]
"exclude": [
"**/*.test.ts",
"lib/**/*"
]
}

0 comments on commit 3a4d356

Please sign in to comment.