-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Caip Types #116
Add Caip Types #116
Changes from 7 commits
7e5ef64
05127fc
0478ad2
0304a09
782e4fb
6d09fb6
c2a686c
488863c
a171671
621e8ae
192ebbf
253c92b
2668bb1
a70473a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { expectAssignable, expectNotAssignable } from 'tsd'; | ||
|
||
import { | ||
Check failure on line 3 in src/caip-types.test-d.ts GitHub Actions / Build, lint, and test / Lint (16.x)
Check failure on line 3 in src/caip-types.test-d.ts GitHub Actions / Build, lint, and test / Lint (18.x)
|
||
CaipAccountId, | ||
CaipChain, | ||
CaipChainId, | ||
CaipNamespace, | ||
CaipNamespaceId, | ||
} from '.'; | ||
|
||
const embeddedString = 'test'; | ||
|
||
// Valid caip strings: | ||
|
||
expectAssignable<CaipChainId>('namespace:reference'); | ||
expectAssignable<CaipChainId>('namespace:'); | ||
expectAssignable<CaipChainId>(':reference'); | ||
expectAssignable<CaipChainId>(`${embeddedString}:${embeddedString}`); | ||
|
||
expectAssignable<CaipAccountId>('namespace:reference:accountAddress'); | ||
expectAssignable<CaipAccountId>('namespace:reference:'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar as above — I'm assuming this is non-enforceable via TypeScript? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
expectAssignable<CaipAccountId>(':reference:accountAddress'); | ||
expectAssignable<CaipAccountId>( | ||
`${embeddedString}:${embeddedString}:${embeddedString}`, | ||
); | ||
|
||
expectAssignable<CaipNamespaceId>('string'); | ||
expectAssignable<CaipNamespaceId>(`${embeddedString}`); | ||
|
||
// Not valid caip strings: | ||
|
||
expectAssignable<CaipChainId>('namespace:😀'); | ||
expectAssignable<CaipChainId>('😀:reference'); | ||
expectNotAssignable<CaipChainId>(0); | ||
expectNotAssignable<CaipChainId>('🙃'); | ||
|
||
expectAssignable<CaipAccountId>('namespace:reference:😀'); | ||
expectAssignable<CaipAccountId>('😀:reference:accountAddress'); | ||
expectNotAssignable<CaipAccountId>(0); | ||
expectNotAssignable<CaipAccountId>('🙃'); | ||
|
||
expectNotAssignable<CaipNamespaceId>(0); | ||
|
||
// Valid caip objects: | ||
|
||
expectAssignable<CaipChain>({ | ||
id: 'string', | ||
name: 'string', | ||
}); | ||
expectAssignable<CaipChain>({ | ||
id: `${embeddedString}`, | ||
name: `${embeddedString}`, | ||
}); | ||
|
||
expectAssignable<CaipNamespace>({ | ||
chains: [ | ||
{ | ||
id: 'string', | ||
name: 'string', | ||
}, | ||
{ | ||
id: `${embeddedString}`, | ||
name: `${embeddedString}`, | ||
}, | ||
], | ||
}); | ||
expectAssignable<CaipNamespace>({ | ||
chains: [ | ||
{ | ||
id: 'string', | ||
name: 'string', | ||
}, | ||
{ | ||
id: `${embeddedString}`, | ||
name: `${embeddedString}`, | ||
}, | ||
], | ||
methods: ['string', `${embeddedString}`], | ||
events: ['string', `${embeddedString}`], | ||
}); | ||
|
||
// Not valid caip objects: | ||
expectNotAssignable<CaipChain>(''); | ||
expectNotAssignable<CaipChain>(0); | ||
expectNotAssignable<CaipChain>({}); | ||
expectNotAssignable<CaipChain>({ | ||
id: 'string', | ||
}); | ||
expectNotAssignable<CaipChain>({ | ||
name: 'string', | ||
}); | ||
expectNotAssignable<CaipChain>({ | ||
id: 0, | ||
name: 'string', | ||
}); | ||
expectNotAssignable<CaipChain>({ | ||
id: 'string', | ||
name: 0, | ||
}); | ||
|
||
expectNotAssignable<CaipNamespace>(''); | ||
expectNotAssignable<CaipNamespace>(0); | ||
expectNotAssignable<CaipNamespace>({}); | ||
expectNotAssignable<CaipNamespace>({ | ||
chains: [ | ||
'', | ||
0, | ||
{}, | ||
{ | ||
id: 'string', | ||
name: 0, | ||
}, | ||
{ | ||
id: 'string', | ||
}, | ||
{ | ||
name: 'string', | ||
}, | ||
], | ||
}); | ||
expectNotAssignable<CaipNamespace>({ | ||
chains: [ | ||
{ | ||
id: 'string', | ||
name: 'string', | ||
}, | ||
], | ||
methods: [0], | ||
}); | ||
expectNotAssignable<CaipNamespace>({ | ||
chains: [ | ||
{ | ||
id: 'string', | ||
name: 'string', | ||
}, | ||
], | ||
events: [0], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming that this is non-enforceable via TypeScript, is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately not. We could try to hack it by doing something like this
But I believe this makes a type with n^2 definitions since they get crossmulitplied