-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: adding more tests for strip-types
- Loading branch information
1 parent
c237eab
commit 240c9e9
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
interface Bar { | ||
name: string; | ||
age: number; | ||
} | ||
|
||
class Test<T> { | ||
constructor(private value: T) {} | ||
|
||
public getValue(): T { | ||
return this.value; | ||
} | ||
} | ||
|
||
const foo = new Test<Bar>({ age: 42, name: 'John Doe' }); | ||
console.log(foo.getValue()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Use Some Union Types Together | ||
const getTypescript = async () => { | ||
return { | ||
name: 'Hello, TypeScript!', | ||
}; | ||
}; | ||
|
||
type MyNameResult = Awaited<ReturnType<typeof getTypescript>>; | ||
const myNameResult: MyNameResult = { | ||
name: 'Hello, TypeScript!', | ||
}; | ||
|
||
console.log(myNameResult); | ||
|
||
type RoleAttributes = | ||
| { | ||
role: 'admin'; | ||
permission: 'all'; | ||
} | ||
| { | ||
role: 'user'; | ||
} | ||
| { | ||
role: 'manager'; | ||
}; | ||
|
||
// Union Type: Extract | ||
type AdminRole = Extract<RoleAttributes, { role: 'admin' }>; | ||
const adminRole: AdminRole = { | ||
role: 'admin', | ||
permission: 'all', | ||
}; | ||
|
||
console.log(adminRole); | ||
|
||
type MyType = { | ||
foo: string; | ||
bar: number; | ||
zoo: boolean; | ||
metadata?: unknown; | ||
}; | ||
|
||
// Union Type: Partial | ||
type PartialType = Partial<MyType>; | ||
|
||
const PartialTypeWithValues: PartialType = { | ||
foo: 'Testing Partial Type', | ||
bar: 42, | ||
zoo: true, | ||
metadata: undefined, | ||
}; | ||
|
||
console.log(PartialTypeWithValues); |